title: Hinnant's stack allocator and exceptions
body: <p>I want to use Hinnant's stack allocator (<a href="http://howardhinnant.github.io/stack_alloc.html" rel="noreferrer">documentation</a>, <a href="http://howardhinnant.github.io/short_alloc.h" rel="noreferrer">implementation</a>) in combination with STL containers but I want to modify it such that <strong>dynamic memory allocation NEVER takes place</strong>. </p>
  
  <p>One thing that must be done to fulfil this is to replace the new/delete calls in the allocate/deallocate methods that take place if there is no room on the stack supplied buffer.</p>
  
  <p>But how should I deal with exceptions? The STL containers may throw exceptions, e.g.</p>
  
  <blockquote>
    <p>std::vector::at</p>
    
    <p>"The function automatically checks whether n is within the bounds of
    valid elements in the vector, throwing an out_of_range exception if it
    is not [...]"</p>
  </blockquote>
  
  <p><a href="http://www.cplusplus.com/reference/vector/vector/at/" rel="noreferrer">http://www.cplusplus.com/reference/vector/vector/at/</a></p>
  
  <p>I could not find a clear answer whether exceptions are stored in dynamic or static memory. Only these lines give hints:</p>
  
  <blockquote>
    <p>From [except.throw]/15.1/4:</p>
    
    <p>The memory for the exception object is allocated in an unspecified
    way, except as noted in 3.7.4.1.</p>
    
    <p>The final reference, [basic.stc.dynamic.allocation]/4, says:</p>
    
    <p>[Note: In particular, a global allocation function is not called to
    allocate storage for [...] an exception object (15.1). — end note]</p>
  </blockquote>
  
  <p><a href="https://stackoverflow.com/a/27259902/8007684">https://stackoverflow.com/a/27259902/8007684</a></p>
  
  <p>What exactly does this mean? Is the memory reserved for exceptions placed in static memory? Or are there still any allocations happening in an "unspecified way" which would mean exceptions would be stored dynamically? The quoted description leads much space for interpretation...</p>
  
  <p><strong>So my basic question is:</strong> Is it safe to use STL containers+Hinnant's stack allocator if dynamic memory usage is forbidden? Or does this not work and I either have to use <code>-fno-exceptions</code> to replace exceptions by <code>abort()</code> calls or implement my own replacements of STL containers that do not throw exceptions...?</p>
  
  <p>Thanks in advance!</p>
  
  <p>inspire</p>