|
|
|
|
||||||
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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? |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 2007-12-28 12:02, mczard@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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Dec 28, 6:02am, 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 T> struct 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 |
|
![]() |
| Outils de la discussion | |
|
|