-
Notifications
You must be signed in to change notification settings - Fork 0
/
UnitTest.cpp
80 lines (68 loc) · 1.43 KB
/
UnitTest.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
/*******************************************************
* This file is part of ConcurrentMemory.
*
* Licensed under the GNU General Public License v3.0;
* you may not use this file except in compliance with the License.
*
* Author: Zhang Tong ([email protected])
*
* Last Modified: 2021Äê12ÔÂ20ÈÕ18µã19·Ö
*
* Content£ºµ¥Ôª²âÊÔ
*******************************************************/
#include "ConcurrentAlloc.h"
void func1()
{
for (size_t i = 0; i < 10; ++i)
{
ConcurrentAlloc(17);
}
}
void func2()
{
for (size_t i = 0; i < 20; ++i)
{
ConcurrentAlloc(5);
}
}
void TestThreads()
{
std::thread t1(func1);
std::thread t2(func2);
t1.join();
t2.join();
}
void TestSizeClass()
{
cout << SizeClass::Index(1035) << endl;
cout << SizeClass::Index(1025) << endl;
cout << SizeClass::Index(1024) << endl;
}
void TestConcurrentAlloc()
{
void* ptr0 = ConcurrentAlloc(5);
void* ptr1 = ConcurrentAlloc(8);
void* ptr2 = ConcurrentAlloc(8);
void* ptr3 = ConcurrentAlloc(8);
ConcurrentFree(ptr1);
ConcurrentFree(ptr2);
ConcurrentFree(ptr3);
}
void TestBigMemory()
{
void* ptr1 = ConcurrentAlloc(65 * 1024);
ConcurrentFree(ptr1);
void* ptr2 = ConcurrentAlloc(129 * 4 * 1024);
ConcurrentFree(ptr2);
}
//int main()
//{
//// TestBigMemory();
////
//// TestObjectPool();
//// TestThreads();
//// TestSizeClass();
// TestConcurrentAlloc();
//
// return 0;
//}