473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

looking for an allocator class

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.

Aug 14 '07 #1
3 1392
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

Aug 14 '07 #2
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?



Aug 14 '07 #3
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.
well on my implementation(VC++ 8.0) it increases by 50%.So it goes
like
1,2,3,4,6,9,13 multiplied by size of whatever you put into it.Not
that
important anyway,they are free to choose as they please.
>
Does the boost allocator mean that there will memory arrays lieing
around
of size 1,2,4,8 that can be reused ?
vector will deallocate the previous array through the allocator,and
it
would probably return the memory to the pool ready for reuse.not
that
there will be single units of different sizes. it uses chunks of some
bytes
appropriate for integers. there may be enough free chunks to allocate
for
the next request.(previous allocation of 8*sizeof(int) bytes are
probably available)
if not, it would cause an allocation
>
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?
It depends on whether there will be enough contigious free memory
left over from whatever allocated for v (Note that v still holds
on memory). It may allocate more than what requested by the first
vector ,and return that extra memory for v2 if the requested size is
small enough to fit in.
Aug 15 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Brian Genisio | last post by:
Hi all, I am developing some software, that creates a tree of information. For each node, currently I am overriding the new operator, because it is a requirement that after initialization, no...
3
by: Bernhard Kick | last post by:
Hi all, I saw this code in the book "Accelerated C++" (chapt 11, iirc): template <class T> class Vec { ... std::allocator<T> alloc; // object to handle memory allocation // ??would static...
13
by: John Harrison | last post by:
If you specify an allocator in an STL container is it a requirement that the allocator allocates object of the right type, or can you assume that the container will rebind the allocator to the...
2
by: Joshua Kolden | last post by:
STL allocators are templates so that when you write one you are obliged to make it work with any type. However, the Intel IPP library that we use has memory aligned allocators for each of 15...
1
by: Fred Zwarts | last post by:
I think I am missing something obvious. Maybe someone can set me on the right track. For some reason (not to be discussed here) I cannot use the normal operator new for a certain map, so I want...
3
by: Protoman | last post by:
Why won't the compiler let me write this: template <class T> class Allocator { public: Allocator(){} T* allocate(){static long long i=0; T* j=new(pool) T; i++; return &*j;} private:
2
by: Protoman | last post by:
Is this a good method of repersenting an allocator?: template <class T, long long X> class Allocator { public: Allocator(){} T* allocate() { static long long i=0;
2
by: * Tong * | last post by:
Hi, I'm following the example in "C++ Templates: The Complete Guide", section 5.4 Template Template Parameters. It's basics/stack8.hpp example has a statement of "#include <allocator>", but I...
16
by: PeterAPIIT | last post by:
Hello all C++ expert programmer, i have wrote partial general allocator for my container. After reading standard C++ library and code guru article, i have several questions. 1. Why...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.