|
Boost Users : |
Subject: [Boost-users] [Pool] correct usage for optimal performance
From: Igor R (boost.lists_at_[hidden])
Date: 2009-12-07 08:31:26
Hello,
In my application I use singleton pools for the 2 most common
allocation scenarios:
1) Frequent allocation of small objects (one by one, tens to hundreds
per second). Every object is disposed soon after its allocation, so
that only few objects are alive simultaniously.
Since the objects are accessed through shared_ptr, I allocate them as follows:
allocate_shared<Obj>(boost::fast_pool_allocator<Obj>());
Is this the appropriate use of Pool for this scenario? Should I use
pool_allocator (i.e. ordered_malloc()) instead?
2) Frequent (same as in (1) frequency and lifetime) allocation of
memory blocks that look like this: [10Kb, 1Kb, 1.1Kb, 0.9Kb,...
10.5Kb...] - i.e. 1 big block, then several small ones. Each block is
stored in shared_array, and I allocate it this way:
shared_array<char> data_;
//...
typedef boost::singleton_pool<my_alloc_tag, 1024> allocator;
int chunks = blockSize / allocator::requested_size + 1; // rough aproximation
data_.reset(static_cast<char *>(allocator::malloc(chunks)),
bind(&allocator::free, _1, chunks));
Again, should I use here ordered_xxx? Or probably it's worth using
allocator::maloc for the case of chunks==1, and ordered_malloc for
chunks > 1?
Thanks!
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