cgma
MemoryBlock.cpp
Go to the documentation of this file.
00001 //-       Class: MemoryBlock
00002 //-       Owner: Jim Hipp
00003 //- Description: MemoryBlock provides stack storage for block or "Chunk"
00004 //-              memory allocated with overloaded 'new' operators in classes
00005 //-              utilizing a MemoryManager object.
00006 //- Checked By: 
00007 //-    Version:
00008 
00009 #include"MemoryBlock.hpp"
00010 
00011 
00012 // destructor: recusively deletes stack of allocated memory
00013 MemoryBlock::~MemoryBlock()
00014 {
00015   delete [] block;
00016   if (next) 
00017   {
00018     delete next;
00019     next = NULL;
00020   }
00021 }
00022 
00023 // retreive total amount of memory allocated (bytes) including all blocks
00024 // beneath 'this' block on the stack
00025 int MemoryBlock::get_memory_allocation()
00026 {
00027   MemoryBlock* block_ptr = this;
00028 
00029   // sum all allocated memory
00030 
00031   int amount = 0;
00032   while (block_ptr)
00033   {
00034     amount += block_ptr->size;
00035     block_ptr = block_ptr->next;
00036   }
00037 
00038   return amount;
00039 }
00040 
00041 
00042 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines