reverting back the changes. causes core dump
[csql.git] / include / HeapAllocator.h
blobfce4d256c0a7b79834fc48e3cb8c1334a7d6e72a
1 /***************************************************************************
2 * *
3 * Copyright (C) Lakshya Solutions Ltd. All rights reserved. *
4 * *
5 ***************************************************************************/
7 #ifndef HEAP_ALLOCATOR
8 #define HEAP_ALLOCATOR
9 #include <os.h>
10 #include <ErrorType.h>
11 #define PAGEINFOSIZE 4
12 #define BLOCKINFOSIZE 4
14 class DllExport VarHeapAllocator
16 void *top;
17 void *last;
18 void *offset;
19 int pageSize;
20 int usedBytes;
21 int mode;
22 int newAllocateCounter;
23 int reAllocateCounter;
24 int pageCounter;
25 int deallocateCounter;
26 int isInitialized;
28 void initializeInfo(void *ptr);
29 void initSize(int size);
31 public:
32 VarHeapAllocator()
34 top = offset = NULL;
35 mode = 0;
36 isInitialized = 0;
37 pageCounter=0;
38 newAllocateCounter=0;
39 deallocateCounter=0;
40 reAllocateCounter=0;
42 void init(int size, int pMode =0);
43 void * allocate(int size);
44 void deallocate(void *);
45 void destroy();
46 void print();
47 void itirate();
49 class DllExport FixedHeapAllocator
51 int blockSize;
52 int usedBytes;
53 int pageSize;
54 int allocateSize;
55 int isInitialized;
56 int newAllocateCounter;
57 int reAllocateCounter;
58 int pageCounter;
59 int deallocateCounter;
61 void *top;
62 void *offset;
63 void initializeInfo(void *ptr);
65 public:
66 FixedHeapAllocator()
68 top = offset = NULL;
69 isInitialized = 0;
70 pageCounter=0;
71 newAllocateCounter=0;
72 deallocateCounter=0;
73 reAllocateCounter=0;
75 void init(int pSize,int allocSize);
76 void *allocate();
77 void deAllocate(void *ptr);
78 void destroy();
80 class DllExport HashMapNode
82 public:
83 void *elem;
84 HashMapNode *next;
85 HashMapNode() { elem = NULL; next = NULL; }
86 void print() { printf("elem:%x next %x\n", elem, next); }
88 class DllExport HashMap
90 void **bucket;
91 int keySize;
92 int bucketSize;
93 bool optGrpIntNoNull;
94 public:
95 HashMap(){ keySize = 0; bucketSize = 1009;
96 bucket = (void**) ::malloc(bucketSize * sizeof(void*));
97 memset(bucket, 0, bucketSize * sizeof(void*));
98 optGrpIntNoNull = false;
100 ~HashMap() { ::free(bucket); }
101 void setKeySize(int size) { keySize = size; }
102 void setGrpIntNoNull(){ optGrpIntNoNull = true; }
103 DbRetVal insert(void *elem);
104 void* find(void *elem);
105 bool remove(void *elem);
106 void removeAll();
109 #endif