I know that in C it is relatively easy to define your own memory management functions (I have written my own, complete with very primitive garbage collector, in an attempt to track down memory leaks before I had heard about Valgrind).

I believe Python essentially does this under the hood by allocating buffers and managing its own memory requests on them (allocating more when it needs more, obviously).

I wonder if it is possible to do this kind of thing in C++? It occurs to me that it might be hard to write platform-independent code which mimics the behaviour of the `new` keyword on a preallocated buffer. A quick Google reveals some syntax[1] that I'd not seen before which allows one to do this, although it looks like your call would look something like:

    MyType* instance = new (my_malloc(sizeof(MyType))) MyType();
which is hardly concise. Perhaps a macro called my_new would allow you to text-transform your way there without as many parens or repeats of MyType.

In any case, asking for all your RAM at the beginning, and then re-blanking and re-using it, is certainly much faster for certain problem types (3D games with physics emulation, some scientific problems.)

[1] http://stackoverflow.com/questions/8301043/create-objects-in...

disclaimer: This post is about reinventing too many wheels, and should be taken with a pinch of salt! Moving malloc calls out of loops (and replacing them with hand-written zeroing functions) is probably the most useful tip in practise.

The allocators that appeared in the first C++ Standard were designed by the Committee and turned out to not be as useful as expected. Both Electronic Arts ( http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n227... , https://github.com/paulhodge/EASTL/ ) and Bloomberg ( http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n185... , https://github.com/bloomberg/bde ) proposed a different approach, which allow what you want. C++11 includes stateful allocators and scoped allocators.