Re: pseudo-specs for a String class

From: Kinkie <gkinkie_at_gmail.com>
Date: Mon, 25 Aug 2008 22:01:48 +0200

On Mon, Aug 25, 2008 at 8:03 PM, Alex Rousskov
<rousskov_at_measurement-factory.com> wrote:
>
>> (04:59:40 AM) ***kinkie is starting to write pseudo-specs for a String
>> class..
>> (04:59:52 AM) kinkie: along the lines of what we talked about.
>
> Hi Kinkie,
>
> I noticed on the IRC that you are starting to work on the String
> class specs. This would be very useful, especially if it solves a few
> general buffering problems along the way.
>
> I have not seen the discussion you refer to yet (I have not fully caught
> up with older squid-dev posts but I do not see any with String in the
> subject) but please coordinate your work with
> http://wiki.squid-cache.org/Features/BetterStringBuffer which has quite
> a few ideas and comments.
>
> If your plans differ from what is being discussed on that Feature page,
> let's try to unify them before you get too far. In fact, since the
> discussion on that page has not resolved all the issues, some
> unification would be required in either case.

They not differ significantly, and I'm currently coding an out-of-tree
merge-friendly prototype.
The basic idea is somewhat similar to JIT strings:
two classes work in tandem: String and String::Buf.
String is the public interface, String::Buf (which is private)
performs memory management.

Data-wise, String is a triplet (char* data, len, Buf*). Data points
into memory managed by the Buf. Multiple strings can share a Buf,
possibly at different offsets. Bufs are allocated slightly bigger than
needed, and some optimization strategies can be performed to make life
easier for the memory manager.
Basic design goals: refcounted, cheap copying, string parsing and
slicing; reasonably-cheap appending (due to strings being
almost-immutable).

I'll put the incomplete code somewhere (Launchpad, probably) for
everyone to review in a few days at most. So far it seems promising,
in about 100 lines of code I have implemented memory management,
instantiation, assignment, appending and some debugging (and certainly
quite a few bugs).

-- 
 /kinkie
Received on Mon Aug 25 2008 - 20:02:02 MDT

This archive was generated by hypermail 2.2.0 : Tue Aug 26 2008 - 12:00:07 MDT