17 using std::runtime_error;
24 chunksize(_csize), index(_csize), memsize(0), wastedspace(0)
29 for(
unsigned int i = 0; i <
mem.size(); i++) {
36 cout <<
"Alloc'd " <<
memsize/(1024*1024.0) <<
" Mb " << endl;
37 cout <<
" wasted " <<
wastedspace/(1024*1024.0) <<
" Mb " << endl;
52 chunk =
new unsigned char[size];
53 memset(chunk, 0, size);
61 chunk = chunk +
index;
75 for(
unsigned int i = 0; i <
mem.size(); i++) {
82 cout <<
"Alloc'd " <<
memsize/(1024*1024.0) <<
" Mb " << endl;
84 unsigned long int wastedspace = 0;
85 for(
unsigned int i = 0; i <
index.size(); i++) {
90 cout <<
"wasted " << wastedspace/(1024*1024.0) <<
" Mb " << endl;
96 for (
unsigned int i = 0; i <
index.size(); i++) {
100 chunk = chunk +
index[i];
111 chunk =
new unsigned char[size];
112 memset(chunk, 0, size);
115 mem.push_back(chunk);
116 index.push_back(size);
121 m_base_ptr(base_ptr), m_size(max_size), m_index(0)
129 cout <<
"Using " <<
m_index <<
" of " <<
m_size <<
" bytes." << endl;
135 throw runtime_error(
"SequentialAllocator memory overflow");
std::vector< unsigned char * > mem
const unsigned int chunksize
SequentialAllocator(unsigned char *base_ptr, unsigned int max_size)
Handle a preallocated memory up to max_size.
unsigned char * allocate(unsigned int size)
unsigned long int wastedspace
unsigned long int memsize
ChunkAllocator(unsigned int _csize=(1<< 20))
PackedChunkAllocator(unsigned int _csize=(1<< 20))
unsigned char * allocate(unsigned int size)
std::vector< unsigned char * > mem
unsigned char * allocate(unsigned int size)
allocator object that gets chunks of memory and then hands parts of them to a user ...
const unsigned int chunksize
unsigned long int memsize
std::vector< unsigned int > index
unsigned char * m_base_ptr