PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Need for custom allocators library
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Need for custom allocators library

Réponse
 
LinkBack Outils de la discussion
Vieux 28/12/2007, 11h02   #1
mczard@poczta.onet.pl
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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?
  Réponse avec citation
Vieux 28/12/2007, 12h29   #2
Erik Wikström
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need for custom allocators library

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
  Réponse avec citation
Vieux 28/12/2007, 14h42   #3
Lance Diduck
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Need for custom allocators library

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
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h55.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,08560 seconds with 11 queries