-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvirtual_memory.hpp
38 lines (33 loc) · 943 Bytes
/
virtual_memory.hpp
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
#ifndef virtual_memory_hpp
#define virtual_memory_hpp
#include <iostream>
#include <vector>
#define MAGIC_NUMBER 8
class VM {
public:
VM(size_t mem_alloc) {
memory_fullness_index = 0;
memory_max_size = mem_alloc;
tb = new unsigned char[memory_max_size];
memory_is_allocated = true;
}
~VM() {
if(memory_is_allocated) {
delete [] tb;
memory_is_allocated = false;
}
std::cout << "Virtual Memory is destroyed.\n";
}
void ClearMemory();
void ResetMemory();
void PrintAvailableMemorySpace();
void NewString(std::string *&s, const char *text);
unsigned char * NewString(const char *s, size_t len);
unsigned char * NewString(const char s, size_t len);
private:
bool memory_is_allocated;
unsigned char *tb;
size_t memory_max_size;
size_t memory_fullness_index;
};
#endif /* virtual_memory_hpp */