|
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:
> 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.
Also, Matthew Wilson compares VLA impleemntations, and they are very
bad, often not working properly in connection with recursion.
auto_buffer simply works.
-Thorsten
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk