-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
35 lines (26 loc) · 1.24 KB
/
test.cpp
File metadata and controls
35 lines (26 loc) · 1.24 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
#include "PagingAllocator.h"
#include <iostream>
int main() {
// Create an allocator with 10 frames
PagingAllocator allocator(10);
std::cout << "[1] Initial memory:\n" << allocator.visualizeMemory() << "\n";
// Simulate allocation by process 1 (e.g., 3 bytes = 3 frames)
allocator.allocate(3, 1);
std::cout << "[2] After allocating 3 frames to PID 1:\n" << allocator.visualizeMemory() << "\n";
// Simulate allocation by process 2 (e.g., 4 bytes = 4 frames)
allocator.allocate(4, 2);
std::cout << "[3] After allocating 4 frames to PID 2:\n" << allocator.visualizeMemory() << "\n";
// Deallocate process 1
allocator.deallocate(1);
std::cout << "[4] After deallocating PID 1:\n" << allocator.visualizeMemory() << "\n";
// Allocate again to see if freed frames are reused
allocator.allocate(2, 3);
std::cout << "[5] After allocating 2 frames to PID 3:\n" << allocator.visualizeMemory() << "\n";
// Deallocate process 2
allocator.deallocate(2);
std::cout << "[6] After deallocating PID 2:\n" << allocator.visualizeMemory() << "\n";
// Deallocate process 3
allocator.deallocate(3);
std::cout << "[7] After deallocating PID 3:\n" << allocator.visualizeMemory() << "\n";
return 0;
}