
13 Aug
2009
13 Aug
'09
10:24 p.m.
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?