|
Boost : |
Subject: Re: [boost] stack-allocated STL-containers
From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2009-08-13 18:24:54
Stefan Strasser wrote:
> so I wrote an allocator that I think is generally useful and could be added
> e.g. to Boost.Array:
>
> void do(int n){
> int buffer[20];
> stack_allocator<int,20> alloc(buffer);
> vector<int,stack_allocator<int,20> > vec(alloc);
> vec.reserve(alloc.max_stack_size());
>
> while(...){
> int tmp; i >> tmp;
> vec.push_back(tmp);
> }
> }
>
> the vector operates on the stack as long as there is enough space, and moves
> to the heap afterwards.
> in most cases there is no dynamic allocation.
An implementation is free to consider any instance of an allocator with
the same arguments passed to the constructor as equal, IIRC.
Does your allocator suffer from this issue?
Also, is the container still copyable properly?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk