00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "mxmemory.h"
00018
00019
00020 namespace mx
00021 {
00022
00023
00024 scoped_memory::~scoped_memory() {
00025 release();
00026 }
00027
00028 void scoped_memory::release() {
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 }
00036
00037 void *scoped_memory::alloc(size_t bytes) {
00038 void *buf = malloc(bytes);
00039 memset(buf, 0, bytes);
00040 allocations.push_back(buf);
00041 return buf;
00042 }
00043
00044 void *scoped_memory::sized_alloc(size_t num, size_t size) {
00045 void *buf = calloc(num, size);
00046 allocations.push_back(buf);
00047 return buf;
00048 }
00049
00050
00051 }
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066