-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryRecord.cpp
More file actions
44 lines (34 loc) · 1.21 KB
/
MemoryRecord.cpp
File metadata and controls
44 lines (34 loc) · 1.21 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
#include "MemoryRecord.h"
#include <iostream>
using namespace std;
MemoryRecord::MemoryRecord(unsigned char * startAddress, unsigned int requestedSize) : startAddress(startAddress), size(requestedSize) {
;
}
bool MemoryRecord::hasSpaceFor(unsigned int requestedSize) const {
return size >= requestedSize;
}
bool MemoryRecord::hasMoreSpaceThan(unsigned int requestedSize) const {
return size > requestedSize;
}
MemoryRecord MemoryRecord::allocated(unsigned int requestedSize) const {
if (!(this->hasSpaceFor(requestedSize)))
throw runtime_error("not enought memory in this record");
if (size <= requestedSize)
throw runtime_error("size has to be greater - somewhere is a problem!");
return MemoryRecord(startAddress + requestedSize, size - requestedSize);
}
unsigned char * MemoryRecord::address() const {
return startAddress;
}
unsigned int MemoryRecord::getSize() const {
return size;
}
bool MemoryRecord::isEmpty() const {
return size == 0;
}
unsigned char * MemoryRecord::next() const {
return startAddress + size;
}
bool MemoryRecord::operator<(const MemoryRecord & other) const {
return startAddress < other.address();
}