-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathModuleTest.h
More file actions
125 lines (105 loc) · 2.01 KB
/
ModuleTest.h
File metadata and controls
125 lines (105 loc) · 2.01 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#pragma once
#include"MemoryManagement.h"
#include<stdlib.h>
#include<vector>
//#include"ThreadCache.h"
void testAlloc()
{
//ThreadCache* tc = new ThreadCache();
srand((int)time(0));
//申请内存
/*void* mem = hcMalloc(8);
cout << mem << std::endl;*/
//申请513个小于等于8字节的内存
/*for (int i = 0; i < 65537; i++)
{
size_t memSize = rand() % 1 + 8;
cout <<i<<" "<< hcMalloc(memSize) << std::endl;
}*/
//随意大小
for (int i = 0; i < 6900; i++)
{
size_t memSize = rand() % 1 + 30 * 1024;
cout << memSize << " " << hcMalloc(memSize) << std::endl;
}
}
void func1()
{
for (size_t i = 0; i < 10; ++i)
{
hcMalloc(17);
}
}
void func2()
{
for (size_t i = 0; i < 20; ++i)
{
hcMalloc(5);
}
}
//多线程
void TestThreads()
{
std::thread t1(func1);
std::thread t2(func2);
t1.join();
t2.join();
}
void TestSizeClass()
{
cout << SizeCalculation::Index(1035) << std::endl;
cout << SizeCalculation::Index(1025) << std::endl;
cout << SizeCalculation::Index(1024) << std::endl;
}
void TestConcurrentAlloc()
{
void* ptr0 = hcMalloc(5);
void* ptr1 = hcMalloc(8);
void* ptr2 = hcMalloc(8);
void* ptr3 = hcMalloc(8);
hcFree(ptr1);
hcFree(ptr2);
hcFree(ptr3);
}
//申请大块内存
void TestBigMemory()
{
void* ptr1 = hcMalloc(65 * 1024);
hcFree(ptr1);
void* ptr2 = hcMalloc(129 * 4 * 1024);
hcFree(ptr2);
}
void TestMallocFree()
{
/*for (int i = 0; i < 100; i++)
{
void* ptr = hcMalloc(8);
cout<<ptr<<std::endl;
if (i % 5 == 0)
hcFree(ptr);
}*/
for (int i = 0; i <= 30000; i++)
{
srand(i);
int size = rand();
size /= 10;
void* ptr = hcMalloc(size);
cout << i <<" "<<size<< " " << ptr << std::endl;
hcFree(ptr);
}
}
void testA()
{
std::vector<void*> ptr;
for (int i = 1; i <= 50000; i++)
{
void* p = hcMalloc(15);
ptr.push_back(p);
}
for (int i = 0; i < 50000; i++)
{
hcFree(ptr[i]);
}
/*cout << ptr[49999] << std::endl;
hcFree(ptr[32422]);*/
}