
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: http://synesis.com.au/software/stlsoft/help/classstlsoft_1_1auto__buffer.htm... I suggested the construction of a similar class in boost for SoC last year. -Thorsten