Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object creation in boost::singleton_pool

I am trying to use boost::singleton_pool to create a large number of objects of a type 'Order' in a highly performance critical multithreaded application. Looking at the documentation, this is what I should be doing,

struct OrderTag{};
typedef boost::singleton_pool<OrderTag, sizeof(Order)> OrderPool; 

boost::singleton_pool has a static member function malloc which returns pointer of the void*, but I need to create objects of the type Order in OrderPool by making calls to its constructor. Shall I be using boost::pool_allocator along with singleton_pool to do so?

Thanks.

like image 260
sank Avatar asked Apr 20 '26 21:04

sank


1 Answers

In short: no. boost::pool_allocator implementation itself uses boost::singleton_pool and provides interface like std::allocator so you can use it with STL containers (but not only STL and not only containers) like vector, list etc. The UserAllocator concept is not something like boost::pool_allocator but it's a thing that controls memory management at the lowest level. For example I wrote UserAllocator that allocates memory via mmap() function and not uses heap at all.

So to create objects of a type 'Order' you should use boost::pool_allocator or boost::fast_pool_allocator. In your case it is not necessary to use boost::singleton_pool directly.

like image 166
Alexander Verbitsky Avatar answered Apr 22 '26 12:04

Alexander Verbitsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!