-
Notifications
You must be signed in to change notification settings - Fork 0
/
对象池.cpp
61 lines (58 loc) · 892 Bytes
/
对象池.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
#include <chrono>
#include <iostream>
#include <thread>
// #include "memorymanager.h"
#include "objectpool.h"
using namespace std;
class A : public ObjectPoolBase<class A,2000>
{
public:
public:
int a[3];
};
class B : public ObjectPoolBase<class B, 2000>
{
public:
public:
int a[30];
};
void testFunc()
{
A* parr[1000];
B* pbrr[1000];
for (int i = 0; i < 1000; ++i)
{
parr[i] = new A;
// pbrr[i] = new B;
}
for (int i = 0; i < 1000; ++i)
{
delete parr[i];
// delete pbrr[i];
}
}
int main()
{
/*thread th[4];
for (int i = 0; i < 4; ++i)
{
th[i] = thread(testFunc);
}
for (int i = 0; i < 4; ++i)
{
th[i].join();
}*/
A* parr[2000];
B* pbrr[2000];
for (int i = 0; i < 2000; ++i)
{
parr[i] = new A;
pbrr[i] = new B;
}
for (int i = 0; i < 2000; ++i)
{
delete parr[i];
delete pbrr[i];
}
// this_thread::sleep_for(std::chrono::seconds(10000));
}