-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmemory.cpp
More file actions
32 lines (26 loc) · 678 Bytes
/
Copy pathmemory.cpp
File metadata and controls
32 lines (26 loc) · 678 Bytes
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
#include <iostream>
#include <stdexcept>
#include <vector>
using namespace std;
/**
* Useless for now
*/
class Memory {
private:
unsigned int size;
vector<int> mem; // actually doesn't need to hold anything
public:
Memory(unsigned int size) : mem(size, 0) {}
int read(unsigned int address) {
if (address > size) {
throw out_of_range("index out of range: " + to_string(address));
}
return mem[address];
}
void write(unsigned int address, int value) {
if (address > size) {
throw out_of_range("index out of range: " + to_string(address));
}
mem[address] = value;
}
};