Boost logo

Boost :

Subject: Re: [boost] [utility] new auto_buffer class --- RFC
From: Cory Nelson (phrosty_at_[hidden])
Date: 2009-03-02 08:09:45


On Mon, Mar 2, 2009 at 4:35 AM, Thorsten Ottosen
<thorsten.ottosen_at_[hidden]> wrote:
> Steven Watanabe skrev:
>>
>> AMDG
>>
>> Mathias Gaunard wrote:
>>>
>>> Thorsten Ottosen wrote:
>>>>
>>>> Basically boost::auto_buffer<T,N> is a C++ version of variable lenght
>>>> array (from C99).
>>>
>>> N is known at compile-time.
>>> Thus I do not see how it is related to C99 VLAs at all.
>>
>> N is not the number of elements in the container.  N controls how much
>> stack storage is allocated.  The number of elements is dynamic.
>
> Exactly.
>
> The idea is that you know ca in advance the maximum number of elements you
> need for your temporary array. For example, in a logging library, you might
> not expect 95% of all lines to be less than 512 chars. Thus you can use
>
>  boost::auto_buffer<char,512> buffer;
>
> to avoid heap-allocations in 95% of the cases. This can be a major
> speed-improvement. For the remaining 5% of the cases, the buffer will be
> placed on the heap, but the code from the user's persective remains the
> same.

I think that sounds very useful. I'd be interested in seeing
something like that in boost. But it's not anything like C99 VLAs, I
wouldn't refer to it as such.

-- 
Cory Nelson

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk