Question

The project I'm working on needs custom memory management, since it uses does a lot of allocations and deallocations. I need to implement stack-like memories and some custom heap-like memories, which work fast with my application. Also, I need the STL containers to use these custom allocators, whenever possible.

Right now, I'm unfamiliar with the best practices of implementing a custom memory manager and I have other priorities to look forward to.

So, given the above requirements, I'm looking for an elegant way of abstracting the memory management internals, so that it can just use new and delete for now, and when required, can be changed to the custom allocators without much headache?

Pardon me for any wrong terminology use!

Was it helpful?

Solution

The standard interface for custom memory allocators in C++ is Allocator concept.

The default implementation, std::allocator, uses new and delete, but you can provide your own later and if you conform to the interface, you can use it with standard collections.

OTHER TIPS

you can write a function or class the provide this two function like Pool::New() and Pool::Delete() and implement with the raw new and delete, and really design it when you are ready.

Some simple template technique may required. Just template-lized the (member)function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top