#include <mxmemory.h>
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 |
Definition at line 31 of file mxmemory.h.
| mx::scoped_memory::scoped_memory | ( | ) | [inline] |
| mx::scoped_memory::~scoped_memory | ( | ) | [virtual] |
scoped_memory pool destructor
Definition at line 24 of file mxmemory.cpp.
References release().
00024 { 00025 release(); 00026 }
| void * mx::scoped_memory::alloc | ( | size_t | len | ) | [virtual] |
alloc data on the heap of len bytes
| len | size of memory chunk in bytes |
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)
| num | number of objects | |
| size | size of object |
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 }
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().
1.5.8