1 /*-----------------------------------------------------------------------
\r
2 File : MemoryManager.h
\r
3 Function : Reserves large blocks of memory and gives pointers to small
\r
4 portions of that block when requested.
\r
5 This improves performance since a unique "LARGE ALLOCATION"
\r
6 of memory is needed (a unique call to malloc).
\r
7 It is also responsible of freeing memory.
\r
8 Last change: 10/03/2004
\r
9 Purpose : Improve hash performance.
\r
10 ------------------------------------------------------------------------*/
\r
12 #ifndef MEMORYMANAGERINCLUDED
\r
13 #define MEMORYMANAGERINCLUDED // only used for hashTable of stopwords
\r
22 #define byte unsigned char
\r
25 #define LARGE_BLOCK_SIZE 1024*256 // Size of the blocks of memory that will be allocated
\r
26 #define MAX_BLOCKS 2048 // Maximum number of blocks of size LARGE_BLOCK_SIZE that
\r
30 * Definition of structure MemoryManager
\r
33 byte *BLOCKS[MAX_BLOCKS]; //array of blocks of size LARGE_BLOCK_SIZE
\r
34 unsigned int currentBlock; //currentBlock in the array of blocks
\r
35 unsigned long remainderBytes; //number of bytes not yet assigned in BLOCKS[currentBlock]
\r
36 byte *availableByte; //pointer to next byte not yet assigned
\r
39 typedef struct sMem *MemoryManager;
\r
42 MemoryManager createMemoryManager(void);
\r
43 void destroyMemoryManager (MemoryManager mm);
\r
44 void getMemoryBlock (MemoryManager mm, byte **dst, const unsigned int size);
\r
45 void createNewMemoryBlock (MemoryManager mm);
\r