Re: pseudo-specs for a String class

From: Alex Rousskov <rousskov_at_measurement-factory.com>
Date: Tue, 26 Aug 2008 16:24:48 -0600

On Wed, 2008-08-27 at 00:03 +0200, Henrik Nordstrom wrote:

> I'll give my view of "strings" and buffers:
...

Thanks for writing this up, Henrik! Lots of valuable bits there,
especially on the relationship among the classes and on class
responsibilities.

The class names feel familiar. Have you posted some related code long
time ago? Was it during Squid3 birth?

> As you already noted MemoryRegion is sufficiently small to be passed
> around by value just like if it was a plain pointer.

... but it should be passed by reference whenever possible to avoid the
hidden overheads of refcounting. Every time we pass or return a String
by value, we create and later destroy at least one copy of a String,
which implies "locking" and "unlocking" the underlying buffer.

The refcouting operation is not necessarily very expensive on its own,
but there are many contexts where it will force extra memory allocations
and, eventually, thread contention. Those contexts are often difficult
to identify by looking at the code. It is not difficult to add a "&" to
the parameter or a local variable declaration and it is good practice to
do so for Strings.

HTH,

Alex.
Received on Tue Aug 26 2008 - 22:25:44 MDT

This archive was generated by hypermail 2.2.0 : Wed Aug 27 2008 - 12:00:06 MDT