diff options
Diffstat (limited to 'utils/Allocator.cc')
-rw-r--r-- | utils/Allocator.cc | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/utils/Allocator.cc b/utils/Allocator.cc index d1bdf8d..3fa5ec8 100644 --- a/utils/Allocator.cc +++ b/utils/Allocator.cc @@ -17,8 +17,8 @@ #include <unistd.h> #include "Signal.h" -/*?class CcuAllocator -The memory manager is implemented through a C++ class called \typ{CcuAllocator}. +/*?class IvlAllocator +The memory manager is implemented through a C++ class called \typ{IvlAllocator}. Each instance of this class is a memory allocator, which delivers memory blocks of a given size. @@ -28,7 +28,6 @@ is stored in a list of free blocks so as to be reused. In the current implementa memory pages are never released. ?*/ - #define CHUNKSIZE 1024 /* @@ -54,7 +53,7 @@ This function is called when there is no more memory. It issues an error message the standard error output, then calls \fun{exit}. ?*/ void -CcuAllocator :: MemoryOverflow () +IvlAllocator :: MemoryOverflow () { static char msg [] = "Memory overflow. Bye ...\n"; @@ -63,10 +62,10 @@ CcuAllocator :: MemoryOverflow () } /*? -Constructor for \typ{CcuAllocator}s. It initializes an allocator for structures of size \var{size}. +Constructor for \typ{IvlAllocator}s. It initializes an allocator for structures of size \var{size}. For implementation reasons, allocated blocks will be at least the size of a pointer. ?*/ -CcuAllocator :: CcuAllocator (unsigned int size) +IvlAllocator :: IvlAllocator (unsigned int size) : BlockSize (SizeInWords (size)), ChunkSize (SizeInWords (CHUNKSIZE)), FreeList (0), @@ -84,21 +83,21 @@ CcuAllocator :: CcuAllocator (unsigned int size) } /*?nodoc?*/ -CcuAllocator :: ~CcuAllocator () +IvlAllocator :: ~IvlAllocator () { } /*? -Allocate a block of memory with an \typ{CcuAllocator}. +Allocate a block of memory with an \typ{IvlAllocator}. This function returns the address of the allocated block, or 0 if the allocation failed for some reason. The allocated block is aligned on a word boundary, and it is {\em not} filled with zeroes. ?*/ void* -CcuAllocator :: Alloc () +IvlAllocator :: Alloc () { #ifdef MEMORY_DEBUG - CcuSignalBlocker b (AllSigs); + IvlSignalBlocker b (AllSigs); void* w = new Word [BlockSize]; return w; #else @@ -114,7 +113,7 @@ CcuAllocator :: Alloc () AllocNext = ((Word*) AllocNext) + BlockSize; if (AllocNext > AllocEnd) { /* here we have to get new chunk */ - CcuSignalBlocker b (AllSigs); + IvlSignalBlocker b (AllSigs); block = new Word [ChunkSize]; if (block == 0) MemoryOverflow (); @@ -127,17 +126,16 @@ CcuAllocator :: Alloc () #endif } - /*? -Free the memory allocated at \var{p} by this \typ{CcuAllocator}. +Free the memory allocated at \var{p} by this \typ{IvlAllocator}. No check is performed, and you should take care that \var{p} was allocated by this allocator. ?*/ void -CcuAllocator :: Free (void* p) +IvlAllocator :: Free (void* p) { #ifdef MEMORY_DEBUG - CcuSignalBlocker b (AllSigs); + IvlSignalBlocker b (AllSigs); delete [] ((Word*) p); #else /* Prepend the block to the list of free blocks */ @@ -146,28 +144,27 @@ CcuAllocator :: Free (void* p) #endif } - #ifdef DOC -/*?class CcuAllocatorOf -The template class \typ{CcuAllocatorOf <OBJECT>} is a generic version of the class -\typ{CcuAllocator} that is designed to allocate memory for objects of the class \typ{OBJECT}. +/*?class IvlAllocatorOf +The template class \typ{IvlAllocatorOf <OBJECT>} is a generic version of the class +\typ{IvlAllocator} that is designed to allocate memory for objects of the class \typ{OBJECT}. The following functions are redefined: ?*/ /*? Build an allocator that will allow blocks with the same size as objects of class \typ{OBJECT}. ?*/ -CcuAllocatorOf :: CcuAllocatorOf () +IvlAllocatorOf :: IvlAllocatorOf () { } /*? -This function is the same as \typ{CcuAllocator}::\fun{Alloc} except that it returns \typ{OBJECT*} +This function is the same as \typ{IvlAllocator}::\fun{Alloc} except that it returns \typ{OBJECT*} instead of \typ{void*}. ?*/ OBJECT* -CcuAllocatorOf :: Alloc () +IvlAllocatorOf :: Alloc () { } |