forked from nbdd0121/GenerationalGC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemorySpace.h
More file actions
65 lines (50 loc) · 1.19 KB
/
MemorySpace.h
File metadata and controls
65 lines (50 loc) · 1.19 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
#ifndef NORLIT_GC_MEMORYSPACE_H
#define NORLIT_GC_MEMORYSPACE_H
#include <cstdint>
#include <cstddef>
namespace norlit {
namespace gc {
struct MemorySpace {
static MemorySpace* New(size_t capacity);
uintptr_t top;
uintptr_t capacity;
uintptr_t topOriginal;
MemorySpace* next = nullptr;
uintptr_t data[1];
private:
MemorySpace(size_t capacity);
public:
void FillUnallocated(uint8_t);
void Destroy();
void Trim(size_t = 0);
void* Allocate(size_t size, bool expand = false);
inline void Clear();
inline void SaveOriginal();
inline char* End();
inline char* Begin();
inline char* OriginalEnd();
};
inline void MemorySpace::SaveOriginal() {
topOriginal = top;
if (next) {
next->SaveOriginal();
}
}
inline char* MemorySpace::OriginalEnd() {
return reinterpret_cast<char*>(this) + topOriginal;
}
inline char* MemorySpace::Begin() {
return reinterpret_cast<char*>(data);
}
inline char* MemorySpace::End() {
return reinterpret_cast<char*>(this) + top;
}
inline void MemorySpace::Clear() {
top = reinterpret_cast<char*>(data)-reinterpret_cast<char*>(this);
if (next) {
next->Clear();
}
}
}
}
#endif