Boost logo

Boost :

From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2007-03-01 02:11:50

Michael Marcin wrote:
> I have functions like say a quartic equation solver that can return a
> variable number of solutions. It would be clean IMO to return or pass
> by reference a std::vector or like container that store the solutions.
> However heap allocation is fairly expensive here so the usual solution
> is to have a local array with max solutions elements and pass that by
> reference into the solver and return the number of solutions. This is
> ugly to use and read. Is there a library for stack-based std-like
> containers? Alternatively is it possible to make an compatible
> stack-based allocator for std::vector using alloca?

You can definitely make a stack-based version of allocators. The
allocator would store a pointer to the local array.
It's still fairly ugly though.

I suggest that you could look at STLSoft's auto_buffer:

I suggested the construction of a similar class in boost for SoC last year.


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