3

What are the best open source memory pools available in c++? I do not want thread safety as application will be single threaded. I primary goal is fast allocation and de-allocation. Bit of more than required memory usage is allowed and more initialization time is ok.

In detail, when i say obj = pool.alloc(), I should get the memory for Object from pool<Object> memory as fast as possible. When I say pool.free(obj), memory pointed by obj (which belongs to pool) must be freed immediately and return the memory to object pool. These operations should not involve any locks. Internally, pool could take bit more memory to manage Objects free/allocated instanaces.

  • Do you mean allocators / managers of memory within a contiguous pool? Can you specify what capabilities you actually need? Also, is only the openness of the source important to you, or don't you maybe also want the ability to copy and use the code yourself? – einpoklum - reinstate Monica Dec 27 '15 at 20:55
  • @einpoklum: edited the question. – rahul.deshmukhpatil Dec 28 '15 at 8:16
  • ... and now I'd like someone to answer as well :-) – einpoklum - reinstate Monica Dec 28 '15 at 13:31
  • The question is still unclear. Memory is never thread-safe, so this is either a misunderstanding or at least does not help. Next, you can't allocate memory faster than the operating system itself. If the C++ heap manager is too slow for you, just use VirtualAlloc(). – Thomas Weller Dec 28 '15 at 13:40
  • @ThomasWeller : You are right, memory is never thread-safe. I am trying to allocate the memory from Pool and not from Operating system. pool.alloc is function of object pool. Now object memory pool does the malloc/new only once during the initialization to allocate memory for millions of the objects. And later only if pool gets full. Pool.delete or Pool.free frees memory in the pool and does not free memory from memory manager. – rahul.deshmukhpatil Dec 29 '15 at 6:32
2

I found boost object_pool to be useful. Boost object_pool could be used within single thread. It does not take any lock while allocating memory or freeing memory to the pool. There is variant of this singleton_pool which is thread-safe memory pool and multiple threads could access singleton_pool simultaneously in concurrent environment. Will post if I find any other open source object memory pool.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.