-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmempool.cpp
More file actions
44 lines (34 loc) · 711 Bytes
/
mempool.cpp
File metadata and controls
44 lines (34 loc) · 711 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
#include <cstdlib>
#include <iostream>
#include "mempool.h"
using namespace std;
MemPool::MemPool()
{
nodes.clear();
}
void *MemPool::memAlloc(size_t size)
{
void *result = ::operator new (size);
if (result != NULL) {
nodes.insert(result);
}
return result;
}
void MemPool::memFree(void *ptrb)
{
if (nodes.find(ptrb) != nodes.end()) {
nodes.erase(ptrb);
::operator delete (ptrb);
}
}
void MemPool::freeAll()
{
set<void *>::iterator it = nodes.begin();
while (it != nodes.end()) {
void *ptr = *it;
//cout << hex << "Freeing " << ptr << dec << endl;
::operator delete (ptr);
it++;
}
nodes.clear();
}