-
Notifications
You must be signed in to change notification settings - Fork 45
/
main.cpp
105 lines (97 loc) · 1.57 KB
/
main.cpp
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
94
95
96
97
98
99
100
101
102
103
104
105
#include <vld.h>
#include "List_Node.h"
#include "MemoryPool.h"
#include <stdlib.h>
#include <stdio.h>
#include <vector>
/**
* Memory Leak Caution! Release memory manually.
*/
MemoryPool* mp = MemoryPool::GetInstance();
class TestMemoryPool
{
private:
int value1 = 10;
int value2 = 20;
float val = 5.9f;
public:
TestMemoryPool(){}
static void* operator new(size_t)
{
return mp->Alloc(sizeof(TestMemoryPool));
}
static void operator delete(void* p) {
mp->FreeAlloc(p);
}
};
class BigClassTest
{
private:
char bc[500];
int v = 10;
char* p = nullptr;
public:
BigClassTest() {
//memset(bc, 0, sizeof(bc));
}
static void* operator new(size_t)
{
return mp->Alloc(sizeof(BigClassTest));
}
static void operator delete(void* p) {
mp->FreeAlloc(p);
}
};
class ThirdMemoryTest
{
private:
int v[100];
std::string s;
public:
ThirdMemoryTest()
{
//memset(v, 0, sizeof(v));
s = "";
}
static void* operator new(size_t)
{
return mp->Alloc(sizeof(ThirdMemoryTest));
}
static void operator delete(void* p)
{
mp->FreeAlloc(p);
}
};
void test()
{
TestMemoryPool* v = nullptr;
for (int i = 0; i < 2050; i++)
{
v = new TestMemoryPool();
}
printf("testing\n");
BigClassTest* b = nullptr;
for (int i = 0; i < 3000;i++)
{
b = new BigClassTest();
}
ThirdMemoryTest* t = nullptr;
for (int j = 0; j < 1920; j++)
{
t = new ThirdMemoryTest();
}
}
int main()
{
test();
int p = 12;
int*q = &p;
short v = p;
ListPool<int>iList;
iList.AddNode(10);
for (int i = 98; i > 1; i /= 10)
{
iList.AddNode(i);
}
printf("List size %u\n", iList.ListSize());
}