mx::scoped_memory Class Reference

#include <mxmemory.h>

List of all members.

Public Member Functions

 scoped_memory ()
virtual ~scoped_memory ()
virtual void * alloc (size_t len)
virtual void * sized_alloc (size_t num, size_t size)
virtual void release ()

Protected Attributes

std::vector< void * > allocations


Detailed Description

a scoped memory pool

Definition at line 31 of file mxmemory.h.


Constructor & Destructor Documentation

mx::scoped_memory::scoped_memory (  )  [inline]

scoped memory pool constructor

Definition at line 34 of file mxmemory.h.

00034 { }

mx::scoped_memory::~scoped_memory (  )  [virtual]

scoped_memory pool destructor

Definition at line 24 of file mxmemory.cpp.

References release().

00024                                       {
00025                 release();
00026         }


Member Function Documentation

void * mx::scoped_memory::alloc ( size_t  len  )  [virtual]

alloc data on the heap of len bytes

Parameters:
len size of memory chunk in bytes
Returns:
void * to memory allocated

Definition at line 37 of file mxmemory.cpp.

References allocations.

00037                                                {
00038                 void *buf = malloc(bytes);
00039                 memset(buf, 0, bytes);
00040                 allocations.push_back(buf);
00041                 return buf;
00042         }

void mx::scoped_memory::release (  )  [virtual]

release this memory pool's allocated resources

Definition at line 28 of file mxmemory.cpp.

References allocations.

Referenced by ~scoped_memory().

00028                                     {
00029                 std::vector<void *>::iterator i, e = allocations.end();
00030                 for(i = allocations.begin(); i != e; i++) {
00031                         void *ptr = *i;
00032                         free(ptr);
00033                 }
00034                 allocations.clear();
00035         }

void * mx::scoped_memory::sized_alloc ( size_t  num,
size_t  size 
) [virtual]

sized alloc (calloc)

Parameters:
num number of objects
size size of object
Returns:
void * to memory allocated

Definition at line 44 of file mxmemory.cpp.

References allocations.

00044                                                                 {
00045                 void *buf = calloc(num, size);
00046                 allocations.push_back(buf);
00047                 return buf;
00048         }


Member Data Documentation

std::vector<void *> mx::scoped_memory::allocations [protected]

allocated pointers

Definition at line 54 of file mxmemory.h.

Referenced by alloc(), release(), and sized_alloc().


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

Generated on Wed Jun 10 14:52:02 2009 for libmx by  doxygen 1.5.8