forked from voipmonitor/sniffer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
heap_chunk.h
86 lines (74 loc) · 2.18 KB
/
heap_chunk.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#ifndef HEAP_CHUNK_H
#define HEAP_CHUNK_H
#ifdef HEAP_CHUNK_ENABLE
class cLocalHeap
{ protected:
struct sHeader
{ unsigned int Size;
sHeader *PrevReal;
sHeader *PrevFree;
sHeader *NextFree;
};
public:
cLocalHeap(unsigned int size,bool initBuff = true,
bool autoDeallocInDestructor = true);
~cLocalHeap();
void *MAlloc(unsigned int sizeOfObject);
void Free(void *pointerToObject);
bool IsOwnItem(const void *pointerToObject);
void InitBuff();
bool Check();
private:
inline void *Alloc(unsigned int size);
inline void *CreateHeap(unsigned int size);
inline void *ExtendHeap(unsigned int size);
inline void *AllocatePartialBlock(sHeader *block,unsigned int size);
inline void PullFreeBlock(sHeader *block);
inline void FreeLastBlock();
inline void FreeInnerBlock(sHeader *block);
inline void InsertFreeBlock(sHeader *block);
inline void JoinFreeBlocks(sHeader *block1,sHeader *block2);
inline void SetBreak(void *pointer);
inline void *IncrementBreak(unsigned int increment);
private:
unsigned int Size;
char *Buff;
char *Break;
sHeader *First;
sHeader *Last;
sHeader *Rover;
bool AutoDeallocInDestructor;
};
void *ChunkMAlloc(unsigned int sizeOfObject);
void ChunkFree(void *pointerToObject);
bool IsChunkAllocItem(const void *pointerToObject);
bool CheckChunkAlloc();
#define MAX_CHUNK_ALLOC_ITEMS 1000
#define DEFAULT_CHUNK_ALLOC_SIZE 100000000
class cChunkAllocHeapItem : public cLocalHeap
{ public:
cChunkAllocHeapItem();
void *MAlloc(unsigned int sizeOfObject);
void Free(void *pointerToObject);
bool IsOwnItem(const void *pointerToObject);
bool Check();
private:
bool Active;
bool Full;
friend class cChunkAllocHeap;
};
class cChunkAllocHeap
{ public:
cChunkAllocHeap();
void *MAlloc(unsigned int sizeOfObject);
void Free(void *pointerToObject);
bool IsOwnItem(const void *pointerToObject);
bool Check();
public:
bool Active;
private:
cChunkAllocHeapItem AllocHeapItems[MAX_CHUNK_ALLOC_ITEMS];
int CountActiveAllocHeapItems;
};
#endif //HEAP_CHUNK_ENABLE
#endif //HEAP_CHUNK_H