-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoffHeapSimulationX.hpp
More file actions
93 lines (73 loc) · 1.7 KB
/
offHeapSimulationX.hpp
File metadata and controls
93 lines (73 loc) · 1.7 KB
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
87
88
89
90
91
92
93
#include <iostream>
#include <fstream>
class OffHeapList;
class OffHeapObjectList {
struct ObjectAddrNode {
void *address;
uintptr_t size;
ObjectAddrNode *next;
};
public:
OffHeapObjectList() :
nodeCount(0),
objTotalSize(0) {
head = NULL;
}
~OffHeapObjectList() {
freeAllList();
}
bool isEmpty();
void printOffHeapObjectStatus();
uintptr_t removeHalfOfNodes(OffHeapList *offHeapList);
bool addObjToList(void *address, uintptr_t size);
private:
ObjectAddrNode *createNewNode(void *address, uintptr_t size);
void printfObject(ObjectAddrNode *node);
void freeAllList();
uintptr_t nodeCount;
uintptr_t objTotalSize;
ObjectAddrNode *head;
};
class OffHeapList {
struct FreeList {
void *lowAddress;
void *highAddress;
uintptr_t size;
FreeList *next;
};
public:
/* Constructor */
OffHeapList(void *startAddress, uintptr_t size)
: nodeCount(0),
totalFreeSpace(size),
biggestFreeSize(0),
biggestFreeSizeAddr(NULL)
{
initFreeList(startAddress, size);
}
/* Destructor */
~OffHeapList() {
printf("Destructor called. Freeing all nodes in FreeList\n");
freeAllList();
}
void initFreeList(void *startAddress, uintptr_t size);
void *findAvailableAddress(uintptr_t size);
bool addEntryToFreeList(void *startAddress, uintptr_t size);
bool isEmpty();
void printFreeListStatus();
uintptr_t getApproximateBiggestFreeSize() {
return biggestFreeSize;
}
void *getBiggestFreeSizeAddr() {
return biggestFreeSizeAddr;
}
private:
void printNode(FreeList *node);
FreeList *createNewNode(void *startAddress, uintptr_t size);
void freeAllList();
FreeList *head;
uintptr_t nodeCount;
uintptr_t totalFreeSpace;
uintptr_t biggestFreeSize;
void *biggestFreeSizeAddr;
};