Re: Stdio.Buffer, need a way to revisit old positions in the output

"Stephen R. van den Berg" <[email protected]>
Newsgroups gmane.comp.lang.pike.user
Message-ID <[email protected]>
Per Hedbor () @ Pike (-) importm?te f?r mailinglistan wrote:
>> Yes, well, apart from the fact that you can't use the add_int32(),
>> there is another difficulty here: the sizeof() and the [] operators
>> are relative to the start of the buffer.  The start is a moving
>> target however, since some of it might have been flushed to the
>> descriptor already.

>That would very much be true with your solution as well, unless as a
>side effect it stopped the data from moving around.

Well, no, the positions my original solution returns and accepts
are offset+len.

>I could implement _a_ deluxe version rather quickly, actually:

>|  object k1 = buffer->start_hstring(size_size);
>|  buffer->add()
>|  .. add stuff ..
>|  k1->end([adjust]);
>|  // updates buffer[k1..k1+size-1] to (size_diff+adjust) or if
>|  // specified to end an explicit value
>!  // if k1 is out of scope, undo sub-adds.

>The main difference is that it is not really a sub-buffer, it is a
>sort-of pointer. It would also need to block reading past the new add
>position.

This sounds just about like the ideal solution to me.

>This is a somewhat over-specialized API, but I have also found myself
>wishing for something along those lines, so perhaps it would be useful.

Yes, please!

>Note that it does not really take all that much time to create new
>buffer objects and add those to the buffer:

Yes, I realise that, but I would like to stick to the don't-copy-data-
around-unless-necessary paradigm.

>buffer->start... solution unless the packets are very large
>(basically, if the memcpy time is bigger than the time it takes to
>create and free the object)

Unfortunately, in the database driver, I have to deal with small (<256 bytes)
and large (>32MB) packets, so it will matter.
-- 
Stephen.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.