Thread overview
Proposal - clear() method for OutBuffer
Aug 29, 2004
Dave
Aug 30, 2004
Dave
Aug 31, 2004
J C Calvarese
Sep 02, 2004
Dave
August 29, 2004
Say you're using an OutBuffer to construct a key for an AA. Right now you either have to new an OutBuffer for each key, or you can use public access to the data members to clear it, like this:

# int[char[]] hash;
# OutBuffer ob = new OutBuffer();
# for(int i; i < BIG_NUMBER; i++) {
#   ob.printf("key_%d",i);
#   hash[ob.toString()] = i;
#   ob.data.length = 0;
#   ob.offset = 0;
# }

(The point is not the contrived example. The point is being able to format a string buffer in a code and runtime efficient way.)

How about if OutBuffer.data and OutBuffer.offset are given private access, and a clear() method is added to OutBuffer that does the same as above?

Perhaps there is a more efficient method, but the above is 4-6x faster than new'ing an OutBuffer for each loop depending on how often the loop is run.

Thanks,

- Dave


August 30, 2004
Hmmm, "given private access" below should most likely be "given protected access".

I haven't had a chance to follow the 3rd Party Phobos threads as closely as I'd like and I don't know if there is even a consensus yet.. Is there now a better place to post/discuss library related issues?

Thanks,

- Dave

Dave wrote:

> 
> Say you're using an OutBuffer to construct a key for an AA. Right now you either have to new an OutBuffer for each key, or you can use public access to the data members to clear it, like this:
> 
> # int[char[]] hash;
> # OutBuffer ob = new OutBuffer();
> # for(int i; i < BIG_NUMBER; i++) {
> #   ob.printf("key_%d",i);
> #   hash[ob.toString()] = i;
> #   ob.data.length = 0;
> #   ob.offset = 0;
> # }
> 
> (The point is not the contrived example. The point is being able to format a string buffer in a code and runtime efficient way.)
> 
> How about if OutBuffer.data and OutBuffer.offset are given private access, and a clear() method is added to OutBuffer that does the same as above?
> 
> Perhaps there is a more efficient method, but the above is 4-6x faster than new'ing an OutBuffer for each loop depending on how often the loop is run.
> 
> Thanks,
> 
> - Dave

August 31, 2004
Dave wrote:
> Hmmm, "given private access" below should most likely be "given protected
> access".
> 
> I haven't had a chance to follow the 3rd Party Phobos threads as closely as

If your referring to the DSLG/Deimos Rising/Phobos Rising discussion, it's still alive and pretty much on track. It's moved over to a forum at dsource, though:

http://www.dsource.org/forums/viewforum.php?f=31

> I'd like and I don't know if there is even a consensus yet.. Is there now a
> better place to post/discuss library related issues?

This newsgroup is probably still the best place to bring these criticisms up.

Walter's still the one who produces those nifty archives with the compiler (and it'll probably be that way forever), and the "Phobos Rising" discussion is still trying to answer fundamental questions like "Who are we?" and "Why are we here?".

> 
> Thanks,
> 
> - Dave
> 
> Dave wrote:
> 
> 
>>Say you're using an OutBuffer to construct a key for an AA. Right now you
>>either have to new an OutBuffer for each key, or you can use public access
>>to the data members to clear it, like this:
>>
>># int[char[]] hash;
>># OutBuffer ob = new OutBuffer();
>># for(int i; i < BIG_NUMBER; i++) {
>>#   ob.printf("key_%d",i);
>>#   hash[ob.toString()] = i;
>>#   ob.data.length = 0;
>>#   ob.offset = 0;
>># }
>>
>>(The point is not the contrived example. The point is being able to format
>>a string buffer in a code and runtime efficient way.)
>>
>>How about if OutBuffer.data and OutBuffer.offset are given private access,
>>and a clear() method is added to OutBuffer that does the same as above?
>>
>>Perhaps there is a more efficient method, but the above is 4-6x faster
>>than new'ing an OutBuffer for each loop depending on how often the loop is
>>run.
>>
>>Thanks,
>>
>>- Dave

-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/
September 02, 2004
Anyone have any comments on the "clear()" method for OutBuffer?

Any code out there that relies on public access to OutBuffer.data and/or OutBuffer.offset?

For the current library, there is one line in std/regexp.d (setting data = null) that would need to be changed if the following was changed in std/outbuffer.d:

#class OutBuffer
#{
#//  ubyte data[];
#//  unit  offset;
#protected:
#    ubyte[] _data;
#    uint    _offset;
#public:
#    ubyte[] data() { return _data; }
#    uint offset() { return _offset; }
#    void clear() { _data.length = 0; _offset = 0; }
#    .
#    .
#    .

Thanks,

- Dave

In article <cgvf7n$2h74$1@digitaldaemon.com>, Dave says...
>
>
>Hmmm, "given private access" below should most likely be "given protected access".
>
>I haven't had a chance to follow the 3rd Party Phobos threads as closely as I'd like and I don't know if there is even a consensus yet.. Is there now a better place to post/discuss library related issues?
>
>Thanks,
>
>- Dave
>
>Dave wrote:
>
>> 
>> Say you're using an OutBuffer to construct a key for an AA. Right now you either have to new an OutBuffer for each key, or you can use public access to the data members to clear it, like this:
>> 
>> # int[char[]] hash;
>> # OutBuffer ob = new OutBuffer();
>> # for(int i; i < BIG_NUMBER; i++) {
>> #   ob.printf("key_%d",i);
>> #   hash[ob.toString()] = i;
>> #   ob.data.length = 0;
>> #   ob.offset = 0;
>> # }
>> 
>> (The point is not the contrived example. The point is being able to format a string buffer in a code and runtime efficient way.)
>> 
>> How about if OutBuffer.data and OutBuffer.offset are given private access, and a clear() method is added to OutBuffer that does the same as above?
>> 
>> Perhaps there is a more efficient method, but the above is 4-6x faster than new'ing an OutBuffer for each loop depending on how often the loop is run.
>> 
>> Thanks,
>> 
>> - Dave
>