473,327 Members | 1,967 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,327 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 1960
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 therefor I thought object_pool could help me to reduce...
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> #include <vector> using namespace System;
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. Below I give a simple example of one way I am...
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 boost::pool<>. I get a compiler error when an object...
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 singleton_pool<alloc_tag, elem_size>::purge_memory() or something...
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() /*2*/ { /*3*/...
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 memory from that pool without returning to the...
6
by: Juha Nieminen | last post by:
I tested the speed of a simple program like this: //------------------------------------------------------------ #include <list> #include <boost/pool/pool_alloc.hpp> int main() { typedef...
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 std::vector< ParamPtr > ParamPtrVector; with:
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.