473,395 Members | 1,403 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,395 software developers and data experts.

Need for custom allocators library

Does anyone knows about some open-source custom allocators libarary? I
need one especially for fast allocations of elements of a fixed size.
This seems to be a very common problem, isn't it?
Dec 28 '07 #1
2 1427
On 2007-12-28 12:02, mc****@poczta.onet.pl wrote:
Does anyone knows about some open-source custom allocators libarary? I
need one especially for fast allocations of elements of a fixed size.
This seems to be a very common problem, isn't it?
I do not know of any specific library but if you search for pool
allocator you should be able to find something.

--
Erik Wikström
Dec 28 '07 #2
On Dec 28, 6:02*am, mcz...@poczta.onet.pl wrote:
Does anyone knows about some open-source custom allocators libarary? I
need one especially for fast allocations of elements of a fixed size.
This seems to be a very common problem, isn't it?
It is a common problem, but no one seems to have a open source library
for this. I've looked everywhere for one, and finally just rolled my
own, which perhaps one day I will open source.
A trick is to create a node that looks like this:
template <class Tstruct MyNode{
typedef
boost::aligned_storage<sizeof(T),boost::alignment_ of<T>::value>
data_t;

};

Then creating an allocator that looks like
template <class T>struct Alloc{
void* allocate(size_t){
void* ret=0;
if(!m_nodes.empty()){
ret=m_nodes.top();
m_nodes.pop();
}else
ret = new MyNode<T>::data_t;
return ret;
}
void deallocate(void*p){
m_nodes.push(p);
}
~Alloc(){
while(!m_nodes.empty()){
delete mnodes.top();
m_nodes.pop();
}
}
std::stack<void*m_nodes;
};
This isn't the fastest allocator in existence. That doesn't exist. But
it is way faster than just using built in new/delete, esp when you
recycle T's a lot. You should easily be able to extrapolate an
allocator from this code tuned to your application.
Lance
Dec 28 '07 #3

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

Similar topics

19
by: regisser | last post by:
I have a quastion for the C++ professionals and members of the C++ standartization commetee. As i know C++ standart requires an allocator to be a templated parameter in every STL container....
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...
18
by: Mark A. Gibbs | last post by:
I'm having yet another headache with making a standard allocator. What behaviour should be expected from the assigment operator? When would it be called? Why is it there at all, when you can't...
15
by: Alex Vinokur | last post by:
I am looking for any custom allocator sample code for std::vector. Thanks. -- Alex Vinokur http://mathforum.org/library/view/10978.html http://sourceforge.net/users/alexvn
15
by: natespamacct | last post by:
Hi All, I'm not sure if I'm dealing with a C++ question or a compiler question, so please forgive me if I'm asking in the wrong spot. If so, maybe someone can direct me to more appropriate spot....
4
by: Phil | last post by:
k, here is my issue.. I have BLOB data in SQL that needs to be grabbed and made into a TIF file and placed on the client (could be in temp internet dir). The reason we need it in TIF format is...
12
by: Noel | last post by:
Hello, I'm currently developing a web service that retrieves data from an employee table. I would like to send and retrieve a custom employee class to/from the webservice. I have currently coded...
11
by: Diego Martins | last post by:
for me, these items are in the 'tricky zone' of C++ does anyone know good material with that? (dealing with subtle details, pitfalls, good practices...) anything like the Effective series from...
26
by: Ravindra.B | last post by:
I have declared a global variable which is array of pointers and allocated memory for each array variable by using malloc. Some thing similar to below... static char *arr; main() { int i;
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.