What C ++ compatible custom allocators are available?

I would like to use some C ++ compatible memory management in the form of a class derived from std::allocator , but I am able to allocate pieces of memory and free them and free them in smaller parts. I just found boost :: pool, but that doesn't match std in the above sense. Is there anything more useful around or should I code it myself?

(Note that std::allocator often useless for allocating many small objects, i.e. when using std::list .)

EDIT to clarify.

Let's say I want to use std::list for many small objects, then the std::allocator implementations that allocate each object with ::new cause significant overhead at runtime (but also memory). It is much more efficient to isolate large pieces of objects and distribute them one by one. To do this, I need a std complex allocator (no need to derive from std::allocator , but must implement the same concept), which can be used with any container of the std library and provides the required memory management, ideally allowing me to tell you how many objects I can highlight separately.

+4
source share
1 answer

GCC provides several extension distributors as an alternative to std::allocator .

You really did not say what your requirements are, so you cannot say whether any of them suits you.

Edit the following OP edit:

Let's say I want to use std::list for many small objects, then the std::allocator implementations that allocate each object with ::new cause significant overhead at runtime (but also memory).

Why and memory? The overhead of additional pointers in each std::list node will be presented regardless of whether the memory comes from new or a custom allocator. You just mean heap bookkeeping to keep track of all the minor markups?

It is much more efficient to isolate large pieces of objects and distribute them one by one.

Did you measure it?

If you do not want the overhead of allocating a large number of individual nodes, are you sure that std::list is the right container? What about vector or deque ?

boost::stable_vector is still node, but has lower memory costs than std::list .

A boost::flat_map<int, T> not a node and can be used instead of std::list<T>

Distributors are complex and not always the best answer to (real or perceived) problems.

+1
source

All Articles