472,328 Members | 1,051 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

boost pool per class...

Hi,

This is not boost related per sť, therefore I'm posing the question
here.

I need to do many small object allocations, and I'm considering
using boost::pool for this. I've contemplated using Coplien's CRTP
to encapsulate the allocation/de-allocation and the pool per type.

Does anybody see a potential caveat here? One potential caveat
would be if the derived class overloads new/delete himself, but
that defeats the point of deriving in the first place. I made
the destructor protected as deletion would be through the
interface of the derived type - so to speak.

Comments welcome.

Werner

Example here:

#include <memory>

//Just to get things to compile...
class Default{};

template <class Alloc = Default>
struct BoostPool
{ explicit BoostPool( unsigned size); };

//Encapsulates small object allocation
// per type.
template <class AllocT>
class BoostPoolAllocatable
{
public:
static void* operator new( size_t );
static void operator delete( void*, size_t );

protected:
virtual ~BoostPoolAllocatable(){ }

private:
static BoostPool<myPool_;
};
template <class AllocT>
BoostPool<BoostPoolAllocatable<AllocT>::myPool_( sizeof(AllocT) );

//The small object...
struct SmallObject : BoostPoolAllocatable<SmallObject>
{
};

//Test
int main()
{
std::auto_ptr<SmallObjectx( new SmallObject );
}
Nov 17 '07 #1
1 1882
On Nov 17, 11:32 am, werasm <wer...@gmail.comwrote:
//Just to get things to compile...
class Default{};

template <class Alloc = Default>
struct BoostPool
{ explicit BoostPool( unsigned size); };

//Encapsulates small object allocation
// per type.
template <class AllocT>
class BoostPoolAllocatable
{
public:
static void* operator new( size_t );
static void operator delete( void*, size_t );

protected:
virtual ~BoostPoolAllocatable(){ }

private:
static BoostPool<myPool_;};

template <class AllocT>
BoostPool<BoostPoolAllocatable<AllocT>::myPool_( sizeof(AllocT) );

//The small object...
struct SmallObject : BoostPoolAllocatable<SmallObject>
{

};
Excuse me for making a habit of replying to my own posts :-|. I
should probably add operator new[] and delete[] operators as
well. Consider it done. Any other comments welcome.
Nov 17 '07 #2

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

Similar topics

0
by: porschberg | last post by:
Hi, I have question regarding the pool library. In my application I read a lot of data records from a database into a small data class and...
1
by: Noah Roberts | last post by:
Trying to use boost::function in a C++/CLI program. Here is code: pragma once #include <boost/function.hpp> #include <boost/shared_ptr.hpp>...
3
by: Chris Jones | last post by:
Hi, I've experimenting with using boost::pool_allocator with std::vector and gcc (4.1)., and I am having problems with segmentation violations....
5
by: mackenzie | last post by:
Hello, I am looking for a little bit of help. I am trying to create a dynamically allocated object which contains one or more objects of type...
3
by: Barry | last post by:
As boost::pool_alloc use singleton holder for pool allocator, client programmers have to reclaim the memory by hand through calling...
3
by: neino | last post by:
Hello, did anyone of You have problems using boost::regex ? That code below : #include "boost/regex.hpp" /*1*/ int main() ...
4
by: mavrik | last post by:
Hi all, I've a requirement of creating a memory pool for all memory needed by my application, when my application starts. And I should take all...
6
by: Juha Nieminen | last post by:
I tested the speed of a simple program like this: //------------------------------------------------------------ #include <list> #include...
0
by: varnie | last post by:
hell-o !~ i faced weird problem during usage boost::pool_allocator. after i've changed: typedef boost::shared_ptr< param > ParamPtr; typedef...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.