-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryManager.h
More file actions
54 lines (37 loc) · 1018 Bytes
/
MemoryManager.h
File metadata and controls
54 lines (37 loc) · 1018 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
50
51
52
53
54
#pragma once
#include <functional>
#include <list>
#include <vector>
using namespace std;
int bestFit(int sizeInWords, void *list);
int worstFit(int sizeInWords, void *list);
struct Block {
unsigned offset;
unsigned size;
bool allocated;
Block();
Block(unsigned offset, unsigned size, bool free);
};
class MemoryManager {
private:
unsigned wordSize;
unsigned memoryLimit;
vector<Block> blocks;
char* arr;
unsigned listSize;
std::function<int(int, void *)> allocator;
public:
MemoryManager(unsigned wordSize, std::function<int(int, void *)> allocator);
~MemoryManager();
void initialize(size_t sizeInWords);
void shutdown();
void *allocate(size_t sizeInBytes);
void free(void *address);
void setAllocator(std::function<int(int, void *)> allocator);
int dumpMemoryMap(char *filename);
void *getList();
void *getBitmap();
unsigned getWordSize();
void *getMemoryStart();
unsigned getMemoryLimit();
};