Stack allocator for C++03 standard containers
Asked Answered
B

1

6

For a software I have to avoid any use of memory in the heap, and only rely on stack-allocated memory. Then, this prevents me from using any C++ standard containers, such as vector, map, string (well, basic_string), which I would really like to use, to ease development and data manipulation.

I found (many) implementations of stack allocators, such as this one which itself references two others, or this one from chromium.

Many of them are not fully compliant with the standard, or rely on C++11 (and I am stuck with C++03 at the moment, sadly). Do you have any feedback about a good already existing stack allocator for C++03 or should I adapt one of the above?

Thanks!

Barbarbarbara answered 28/10, 2015 at 14:9 Comment(1)
Howard Hinnant gives a C++03 bolierplate for his allocator also see Questions about Hinnant's stack allocatorSpark
R
4

Howard Hinnant's short_alloc.h (see also here) is a pretty good start (you will need to add C++03 boilerplate, see here).

Of course, this will still go to the heap if it runs out of memory, the alternative is to throw std::bad_alloc.

Richela answered 29/10, 2015 at 1:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.