Re: [RFC] Time to talk about StringNG merge again?

From: Alex Rousskov <rousskov_at_measurement-factory.com>
Date: Sat, 27 Jul 2013 12:31:26 -0600

On 07/27/2013 12:00 PM, Kinkie wrote:
>> > 1a. Reserve total buffer capacity. Ensure exclusive buffer ownership.
>> >
>> > 1b. Reserve buffer space. Ensure exclusive buffer ownership.
>> >
>> > 2. Reserve N space bytes for the caller to append to. No guarantees
>> > regarding buffer ownership are provided.

> I like Amos's suggestion more (two methods for the append-friendly
> optimization, and one for accessing the internals).

There should be no need for two methods for append-friendly optimization
because append only cares about the space size, not total size. This is
method #2 in the above list.

Methods #1a and #1b ensure exclusive ownership. They do not return a
pointer. They must not contain that append-friendly optimization!

AFAICT, Amos explanation of what I was getting at is correct. His email
did not discuss the optimization trick which is one more reason why we
want rawSpace(), but I think we both suggest the same set of three methods:

// 1a.
void reserveCapacity(size_type minCap) {
    cow(minCap);
}

// 1b.
void reserveSpace(size_type minSpace) {
    // check that the sum below does not exceed size_type
    Must(size() <= size_type's limit - minSpace);
    reserveCapacity(size() + minSpace);
}

// 2.
char *rawSpace(size_type minSpace) {
    ... your optimization goes here ...
    return pointer to space;
}

Needless to say, it is critical to document these correctly and clearly
so that we do not have to come back to this discussion again.

HTH,

Alex.
Received on Sat Jul 27 2013 - 18:31:42 MDT

This archive was generated by hypermail 2.2.0 : Sun Jul 28 2013 - 12:00:06 MDT