Sign in to follow this  
Samurai Jack

How to use Boost Pool?

Recommended Posts

Greetings! I am writing a resource management system for my small game and I would like to have all my memory allocations inside one huge pointer (pool). Istead of new/delete i would like to use some fake new/delete functions that would just provide some allready alocated area that is currently available. Since I do not want to reinvent the wheel I though I could take BOOST::Pool but there are no examples how to use them? Could anyone give me some more details or perhaps a small sample how to use it? I saw 6 or 12 .hpp headers and do not know how to handle. Thank you in advance!

Share this post


Link to post
Share on other sites
Thank you for your fast reply.
My problem is, that I would like one memory pool for various sizes.
It seems that boost is not the correct solution.

Boost looks like this:

boost::pool<> p(sizeof(int));
/* what could look like this:
boost::pool<> p(4);
*/

i could say:
int* pint = p.malloc();

I will get only one 4 byte pointer.

What if I would like to say:
char* pszString = p.malloc(13);

Is something like that possible or is it the wrong container?

I would like to store extracted files. For example:
5 files of various size in one huge buffer.

I am having a zip and a tar file and i would like to extract textures into memory.

Share this post


Link to post
Share on other sites
Quote:
Original post by Samurai Jack
My problem is, that I would like one memory pool for various sizes.

Then Boost.Pool isn't what you are looking for, to quote the documentation:
Quote:
Each of the chunks in any given block are always the same size. This is the fundamental restriction of Simple Segregated Storage: you cannot ask for chunks of different sizes. For example, you cannot ask a Pool of integers for a character, or a Pool of characters for an integer (assuming that characters and integers are different sizes).


For more general info on Boost.Pool and heap allocations, I suggest that you read Pool Concepts.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this