-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpagePool.cpp
59 lines (41 loc) · 1.08 KB
/
pagePool.cpp
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
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include "pagePool.h"
bool PagePool::isEmpty() {
return currAddr == endAddr;
}
void PagePool::askForMoreSpace() {
Address rawSpace = (Address)malloc(MALLOC_REQUEST_SIZE);
#pragma GCC diagnostic ignored "-Wpointer-arith"
if (rawSpace == NULL){
startAddr = endAddr = currAddr = 0;
return;
}
truncate(rawSpace); // make the start of the object a multiple of 4096
}
void PagePool::truncate(Address space) {
int offset = space % 4096;
if (offset) {
startAddr = space + 4096 - offset;
endAddr = startAddr + 255 * 4096;
}else{
startAddr = space;
endAddr = space + MALLOC_REQUEST_SIZE;
}
currAddr = startAddr;
}
Address PagePool::requestNewPage() {
if (this->isEmpty()) {
this->askForMoreSpace();
if (currAddr == 0){
return 0;
}
}
Address beginningOfPage = currAddr;
currAddr += 4096;
return beginningOfPage;
}
PagePool::PagePool() {
this->startAddr = this->endAddr = this->currAddr = 0;
}