-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTinyObjectPoolTest.cpp
More file actions
49 lines (38 loc) · 877 Bytes
/
TinyObjectPoolTest.cpp
File metadata and controls
49 lines (38 loc) · 877 Bytes
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
#include "TinyObjectPool.h"
#include <cstdio>
class Object {
public:
bool init(char param1, short param2, int param3, long long param4) {
mMember1 = param1;
mMember2 = param2;
mMember3 = param3;
mMember4 = param4;
return true;
}
void printSelf() {
printf("self addr = %p\n", this);
}
private:
char mMember1;
short mMember2;
int mMember3;
long long mMember4;
};
int main() {
TinyObjectPool<Object> pool;
Object* obj1 = pool.newInstance();
obj1->init('a', 1, 1, 1);
obj1->printSelf();
Object* obj2 = pool.newInstance();
obj2->init('b', 2, 2, 2);
obj2->printSelf();
pool.recycleInstance(obj1);
pool.recycleInstance(obj2);
Object* obj3 = pool.newInstance();
obj3->init('c', 3, 3, 3);
obj3->printSelf();
Object* obj4 = pool.newInstance();
obj4->init('d', 4, 4, 4);
obj4->printSelf();
return 0;
}