Boost logo

Boost :

Subject: Re: [boost] [utility] new auto_buffer class --- RFC
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2009-03-02 07:35:37

Steven Watanabe skrev:
> 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.


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

Also, Matthew Wilson compares VLA impleemntations, and they are very
bad, often not working properly in connection with recursion.
auto_buffer simply works.


Boost list run by bdawes at, gregod at, cpdaniel at, john at