I want to use Hinnant's stack allocator (documentation, implementation) in combination with STL containers but I want to modify it such that dynamic memory allocation NEVER takes place.
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.
But how should I deal with exceptions? The STL containers may throw exceptions, e.g.
std::vector::at
"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 [...]"
http://www.cplusplus.com/reference/vector/vector/at/
I could not find a clear answer whether exceptions are stored in dynamic or static memory. Only these lines give hints:
From [except.throw]/15.1/4:
The memory for the exception object is allocated in an unspecified way, except as noted in 3.7.4.1.
The final reference, [basic.stc.dynamic.allocation]/4, says:
[Note: In particular, a global allocation function is not called to allocate storage for [...] an exception object (15.1). — end note]
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...
So my basic question is: 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 -fno-exceptions
to replace exceptions by abort()
calls or implement my own replacements of STL containers that do not throw exceptions...?
Thanks in advance!
inspire