// =================================================================== // $Id: allocgo2.h $ // // allocgo2.h // Header file for different type of allocators // // Class: CAllocator, CAllocSub // // REPLACEMENT_STRING // // Copyright by Vlastimil Havran, 2006 - email to "vhavran AT seznam.cz" // Initial coding by Vlastimil Havran, November 2005 #ifndef __ALLOCGO2_H__ #define __ALLOCGO2_H__ // GOLEM headers #include "configh.h" namespace GtpVisibilityPreprocessor { // ------------------------------------------------------------------------ // ************* size-equal item allocator with alligning in the cache **** // size-equal item allocator for ordinary subtree representation with cache // line alligning, sizeItem is the size of the smallest allocated block, // count is the number of items to perform one skip in the allocator forward // ------------------------------------------------------------------------- class CAllocContinuous { public: // constructor .. the size of one allocated item in Bytes, number of items // allocated in one block, the allignment for one entry, the allignment // for the first allocated variable in the new blcok. CAllocContinuous(int sizeEntryV, int numEntriesInBlock, int maxItemsForAllocation = 1, int allignEntrySizeV = 1, int allignBlockSizeV = 1); ~CAllocContinuous() { ReleaseMemory(); } // alloc the memory of size "sizeItem*entriesCnt" alligned in the memory // started in the new block void* NewEntryInNewBlock(int entriesCnt = 1); // alloc the memory of size "sizeItem*entriesCnt" alligned in the memory // it has to be in the current block void* New(int entriesCnt = 1); // alloc the memory of size "sizeItem*entriesCnt" alligned in the memory // it can be in the current block, which is definitely the last one in // the current block. This should be used only if function New() above // returns 0. void* NewLastEntry(int entriesCnt = 1); // alloc next block of size = granularity and returns the address to // the first entry to be allocated in the next allocation by New() functions void* AllocNewBlock(); #if 0 // alloc the memory of size "sizeItem*entriesCnt" alligned in the memory // it has to be in the current block, but it is alligned to the allignment // specified as the parameter. void* NewAlligned(it entriesCnt = 1, int allignment = 4); #endif void ReleaseMemory(); // releases all memory alloc. by Alloc // Returns the allignment unsigned long GetEntryAllignment() const { return allignEntrySize;} unsigned long GetBlockAllignment() const { return allignBlockSize;} unsigned long GetFreeEntryCnt() const { return remainItems; } unsigned long GetBytesAllocated() const { return bytesAllocated;} void Report(); private: // Input variables int granularity; // num of basic items in one block int sizeOfEntry; // size of one item to be allocated int maxItemsAtOnce; // the number of items to be allocated at once int allignBlockSize; // the allignment of the first entry in the block int allignEntrySize; // the allignment of the individual entry // The memory required to allocate for a new block unsigned long memoryForOneBlock; // The status variables unsigned long bytesAllocated; // the count of bytes allocated by this allocator void *initMemBlock; // initial memory block void *lastValidAddress; // the maximum address to be used in the current block void **mstor; // where store allocated memory char *nextAllocp; // next returned addr bool lastEntryInBlockAllocated; // if we have allready used the last entry in the block unsigned long remainItems; // items remains in the block }; } #endif // __ALLOCGO2_H__