-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheasy_alloc.hpp
More file actions
41 lines (37 loc) · 797 Bytes
/
easy_alloc.hpp
File metadata and controls
41 lines (37 loc) · 797 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
#pragma once
#include <functional>
#include "easy_alloc.h"
class CEasyAlloc {
protected:
EasyAlloc _alloc;
public:
CEasyAlloc() {
EasyAllocInit(&_alloc);
}
unsigned Remaining() {
return EasyAllocRemaining(&_alloc);
}
void AddBlock(void *mem, unsigned size) {
EasyAllocAdd(&_alloc, mem, size);
}
void *Alloc(unsigned size) {
return EasyAllocAlloc(&_alloc, size);
}
void *Malloc(unsigned size) {
return EasyAllocMalloc(&_alloc, size);
}
void Free(void *ptr) {
EasyAllocFree(&_alloc, ptr);
}
void Merge() {
EasyAllocMerge(&_alloc);
}
// DEBUG
void ForEachBlock(const std::function<void(void *)> &fn) {
for (EasyAllocNode *p = _alloc.head.next; p; ) {
EasyAllocNode *node = p;
p = p->next;
fn(node);
}
}
};