-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemoryManager.h
59 lines (48 loc) · 1.26 KB
/
MemoryManager.h
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
//
// Created by mikes on 3/22/2022.
//
#pragma once
#include <functional>
#include <vector>
#include <cstdint>
#ifndef BEST_FIT
#define BEST_FIT
int bestFit(int sizeInWords, void *list);
#endif
#ifndef WORST_FIT
#define WORST_FIT
int worstFit(int sizeInWords, void *list);
#endif
class MemoryManager {
struct block
{
bool free;
unsigned int offset;
unsigned int length;
block* next;
block* prev{};
block(unsigned int offset, unsigned int length, block* next, block* prev, bool free);
uint64_t* begin;
};
private:
unsigned int wordSize;
unsigned int memSize;
std::function<int(int, void*)> allocator;
block* head;
block* tail;
uint64_t* mem;
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();
};