Stack-buffer based STL allocator? <p>I was wondering if it practicable to have an C++ standard library compliant <code>allocator</code> that uses a (fixed sized) buffer that lives on the stack.</p> <p>Somehow, it seems this question has not been ask this way yet on SO, although it <em>may</em> have been implicitly answered elsewhere.</p> <p>So basically, it <em>seems</em>, as far as my searches go, that it should be possible to create an allocator that uses a fixed size buffer. Now, on first glance, this should mean that it should <em>also</em> be possible to have an allocator that uses a fixed size buffer that "lives" on the stack, but it <em>does appear</em>, that there is no widespread such implementation around.</p> <p>Let me give an example of what I mean:</p> <pre><code>{ ... char buf[512]; typedef ...hmm?... local_allocator; // should use buf typedef std::basic_string&lt;char, std::char_traits&lt;char&gt;, local_allocator&gt; lstring; lstring str; // string object of max. 512 char } </code></pre> <p>How would this be implementable?</p> <hr> <p>The <a href="http://stackoverflow.com/questions/771458/improvements-for-this-c-stack-allocator">answer to this other question</a> (thanks to R. Martinho Fernandes) links to a stack based allocator from the chromium sources: <a href="http://src.chromium.org/viewvc/chrome/trunk/src/base/stack_container.h">http://src.chromium.org/viewvc/chrome/trunk/src/base/stack_container.h</a></p> <p>However, this class seems extremely peculiar, especially since this <code>StackAllocator</code> <em>does not have a default ctor</em> -- and there I was thinking that <a href="http://www.cplusplus.com/reference/std/memory/allocator/allocator/">every allocator class needs a default ctor</a>.</p>