Boost logo

Boost Users :

Subject: Re: [Boost-users] Zero-malloc memory pool for Boost Intrusive smart pointers
From: Gavin Lambert (boost_at_[hidden])
Date: 2019-03-22 04:44:27


On 22/03/2019 13:09, Francesco wrote:
> I have developed for my needs a C++11 memory pool that can provides C++
> object instances in the form of boost::intrusive_ptr<> that
> automatically return to the pool once their refcount goes to zero.
>
> I found the need for such memory pool to have a zero-malloc memory pool
> algorithm for some performance-oriented applications that were relying
> on std::shared_ptr<>.
>
> Here's the link in case anybody is interested:
> https://github.com/f18m/boost-intrusive-pool
> with some (initial) benchmark as well.

Did you look at std::make_shared<T>? It avoids the double allocation
for the control block that you're complaining about. (Although you
couldn't use it to allocate an arena block in this case -- while it does
support array allocation, there is then only one control block for the
whole array.)

Also the use of default construction and explicit recycle methods (and
requiring boost_intrusive_pool_item as a base class) is ugly.

You should be able to instead keep your pool_item type internal (not
exposed to the consumer) and use aligned_storage to hold uninitialised
storage for the actual item data, calling T's constructor and destructor
as needed to allocate and recycle the slot. (Or just wrap it in
std/boost::optional, although that can introduce some nesting ambiguities.)


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net