X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=swcsa%2Futils%2FMemoryManager.h;fp=swcsa%2Futils%2FMemoryManager.h;h=fb51e63f3944c79afd080b35e286ce7f1fdc038c;hb=102e33b134075765e6d4e0c38bc1307568ce5602;hp=0000000000000000000000000000000000000000;hpb=ed61d2042a7ad7dd83bae32d7c31e69504dafa80;p=SXSI%2FTextCollection.git diff --git a/swcsa/utils/MemoryManager.h b/swcsa/utils/MemoryManager.h new file mode 100755 index 0000000..fb51e63 --- /dev/null +++ b/swcsa/utils/MemoryManager.h @@ -0,0 +1,47 @@ +/*----------------------------------------------------------------------- + File : MemoryManager.h + Function : Reserves large blocks of memory and gives pointers to small + portions of that block when requested. + This improves performance since a unique "LARGE ALLOCATION" + of memory is needed (a unique call to malloc). + It is also responsible of freeing memory. + Last change: 10/03/2004 + Purpose : Improve hash performance. + ------------------------------------------------------------------------*/ + +#ifndef MEMORYMANAGERINCLUDED +#define MEMORYMANAGERINCLUDED // only used for hashTable of stopwords + +#include +#include +#include +#include +#include + +#ifndef byte + #define byte unsigned char +#endif + +#define LARGE_BLOCK_SIZE 1024*256 // Size of the blocks of memory that will be allocated +#define MAX_BLOCKS 2048 // Maximum number of blocks of size LARGE_BLOCK_SIZE that + // can be allocated + + /* + * Definition of structure MemoryManager + */ + struct sMem { + byte *BLOCKS[MAX_BLOCKS]; //array of blocks of size LARGE_BLOCK_SIZE + unsigned int currentBlock; //currentBlock in the array of blocks + unsigned long remainderBytes; //number of bytes not yet assigned in BLOCKS[currentBlock] + byte *availableByte; //pointer to next byte not yet assigned + } ; + + typedef struct sMem *MemoryManager; + + + MemoryManager createMemoryManager(void); + void destroyMemoryManager (MemoryManager mm); + void getMemoryBlock (MemoryManager mm, byte **dst, const unsigned int size); + void createNewMemoryBlock (MemoryManager mm); + +#endif