Added simple WCSA
[SXSI/TextCollection.git] / swcsa / utils / MemoryManager.h
diff --git a/swcsa/utils/MemoryManager.h b/swcsa/utils/MemoryManager.h
new file mode 100755 (executable)
index 0000000..fb51e63
--- /dev/null
@@ -0,0 +1,47 @@
+/*-----------------------------------------------------------------------\r
+ File       : MemoryManager.h\r
+ Function   : Reserves large blocks of memory and gives pointers to small\r
+              portions of that block when requested.\r
+              This improves performance since a unique "LARGE ALLOCATION"\r
+              of memory is needed (a unique call to malloc).\r
+              It is also responsible of freeing memory.\r
+ Last change: 10/03/2004\r
+ Purpose    : Improve hash performance.\r
+ ------------------------------------------------------------------------*/\r
+\r
+#ifndef MEMORYMANAGERINCLUDED\r
+#define  MEMORYMANAGERINCLUDED      // only used for hashTable of stopwords\r
+       \r
+#include <string.h>\r
+#include <stdlib.h>\r
+#include <math.h>\r
+#include <stdio.h>\r
+#include <malloc.h>\r
+\r
+#ifndef byte\r
+       #define byte unsigned char\r
+#endif \r
+\r
+#define LARGE_BLOCK_SIZE 1024*256                      // Size of the blocks of memory that will be allocated\r
+#define MAX_BLOCKS 2048                                                // Maximum number of blocks of size LARGE_BLOCK_SIZE that\r
+                                                                                       // can be allocated\r
+\r
+       /*\r
+        * Definition of structure MemoryManager\r
+        */\r
+       struct sMem {\r
+               byte *BLOCKS[MAX_BLOCKS];                       //array of blocks of size LARGE_BLOCK_SIZE\r
+               unsigned int  currentBlock;                     //currentBlock in the array of blocks\r
+               unsigned long remainderBytes;           //number of bytes not yet assigned in BLOCKS[currentBlock]\r
+               byte *availableByte;                            //pointer to next byte not yet assigned\r
+       } ;\r
+\r
+       typedef struct sMem *MemoryManager;\r
+       \r
+\r
+       MemoryManager createMemoryManager(void);\r
+       void destroyMemoryManager (MemoryManager mm);\r
+       void getMemoryBlock (MemoryManager mm, byte **dst, const unsigned int size);\r
+       void createNewMemoryBlock (MemoryManager mm);\r
+\r
+#endif\r