-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
66 lines (51 loc) · 1.3 KB
/
main.cpp
File metadata and controls
66 lines (51 loc) · 1.3 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
/*
* main.cpp
*
* Created on: 07/07/2013
* Author: eugenio
*/
#include <iostream>
#include <list>
#include "MemoryManager/MemoryPool.hpp"
using namespace std;
/*
class Test {
static MemoryPool mpool;
void* operator new () {
return mpool.getNewElement();
}
void operator delete(void* ptr) {
mpool.returnElement((Test*)ptr);
}
};
MemoryPool Test::mpool(sizeof(Test), 5, 0.6);*/
int main() {
MemoryPool pool(sizeof(int), 3, 0.5);
list<void*> pointers;
for(int i = 0; i < 50; ++i) {
pointers.push_back(pool.getNewElement());
*((int*)pointers.back()) = i;
}
for(list<MemoryPool::MemoryUnit*>::iterator it = pointers.begin(), end = pointers.end(); it != end; ++it) {
static int i = 0;
cout << "indice " << i++ << " vale: " << *((int*)*it) << '\n';
}
cout << endl;
for(int i = 0; i < 25; ++i) {
pool.returnElement(pointers.front());
pointers.pop_front();
}
for(int i = 0; i < 25; ++i) {
pointers.push_back(pool.getNewElement());
*((int*)pointers.back()) = 50-i;
}
for(list<MemoryPool::MemoryUnit*>::iterator it = pointers.begin(), end = pointers.end(); it != end; ++it) {
static int i = 0;
cout << "indice " << i++ << " vale: " << *((int*)*it) << '\n';
}
for(int i = 0; i < 50; ++i) {
pool.returnElement(pointers.front());
pointers.pop_front();
}
return 0;
}