Debug swcsa
[SXSI/TextCollection.git] / swcsa / utils / MemoryManager.h
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
11 \r
12 #ifndef MEMORYMANAGERINCLUDED\r
13 #define  MEMORYMANAGERINCLUDED      // only used for hashTable of stopwords\r
14 \r
15 #include <string.h>\r
16 #include <stdlib.h>\r
17 #include <math.h>\r
18 #include <stdio.h>\r
19 //#include <malloc.h>\r
20 \r
21 #ifndef byte\r
22         #define byte unsigned char\r
23 #endif\r
24 \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
27                                                                                         // can be allocated\r
28 \r
29         /*\r
30          * Definition of structure MemoryManager\r
31          */\r
32         struct sMem {\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
37         } ;\r
38 \r
39         typedef struct sMem *MemoryManager;\r
40 \r
41 \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
46 \r
47 #endif\r