Pool Class Reference

A Pool maintains a set of page-sized chunks of memory, and hands out small blocks very quickly. More...

#include <Pool.h>

Collaboration diagram for Pool:

Collaboration graph
[legend]

List of all members.

Classes

struct  Link

Public Member Functions

 Pool (size_t sz)
 Pool ()
 ~Pool ()
void * alloc ()
void free (void *b)


Detailed Description

A Pool maintains a set of page-sized chunks of memory, and hands out small blocks very quickly.

It does this by considering the large chunks to be a set of small blocks and connecting the blocks in a singly linked list. When asked to hand over a block, it returns first one in the list. When a block is handed back, it goes at the front of the list.

The intent is that a user class will have a static Pool and implement new and delete operators that use the pool to get memory. For example, if the user is building a lightweight Node class, the relevant parts would look like:

class Node { public:

// Get memory from the pool. // Don't need to pass the size_t to the pool because // that is in the ctor for the pool. void *operator new(size_t) { return pool_s.alloc() }

// Return memory to the pool. // Once again, the size_t is already in the pool. void *operator delete(void *p, size_t) { pool_s.free(p); }

private:

// The static memory pool. static Pool pool_s; };

Then in the Node.cpp file you would have:

// Initialize the memory pool with the size of the blocks it will manage. Pool Node::pool_s(sizeof(Node));


Constructor & Destructor Documentation

Pool::Pool ( size_t  sz  ) 

Pool::Pool (  ) 

Pool::~Pool (  ) 


Member Function Documentation

void* Pool::alloc (  )  [inline]

void Pool::free ( void *  b  )  [inline]


The documentation for this class was generated from the following file:

Generated on Wed Mar 16 06:20:26 2011 for FreePOOMA by  doxygen 1.5.9