On Aug 14, 10:02 am, hurcan solter <hsol...@gmail.comwrote:
Does anybody have a good allocator class for allocating lots of small
objects in chunks ? Preferably one that is thread safe - or one that
can be easily made thread safe - I can add the locking myself.
Basically I'm working on some code where much of the time is spent in
allocating objects that are pretty small in size. Many, many of these
objects are allocated.
alexandrescu's Modern C++ Design has a chapter on it.And probably in
the Loki library.Rest of the book is useful too.
There is also Boost Pool library for you to consider
Hurcan Solter
Thanks. I'm checking out the Boost Library now. Suppose we do the
following:
std::vector<int, boost::pool_allocator<int v;
for (int i = 0; i < 10; ++i)
v.push_back(-1);
And the std::vector<intis implemented so that it starts out with
reserved
space of 1 and doubles space every time. So At the end of the above
loop
v will have size 10 and reserved size 16.
Does the boost allocator mean that there will memory arrays lieing
around
of size 1,2,4,8 that can be reused ?
Eg if you do this:
std::vector<int, boost::pool_allocator<int v;
for (int i = 0; i < 10; ++i)
v.push_back(-1);
std::vector<int, boost::pool_allocator<int v2;
for (int i = 0; i < 8; ++i)
v2.push_back(-1);
There will be no system call needed to get more memory -
v2 will just reuse the memory in the pool_allocator<int?