A command-line simulator for variable-partition memory allocation with:
- Best Fit (
B) - Worst Fit (
W) - First Fit (
F)
It supports allocation requests, release requests, compaction, and memory-status reporting.
The simulator is implemented and working as an interactive CLI program.
- Startup prompt prints
Simulator - First input must be total memory size (integer)
- Process IDs are treated as numeric IDs
STATprints memory ranges in ascending order as either allocated PID orHole
Compile both translation units:
g++ -std=c++11 -Wall -Wextra -pedantic main.cpp core/manager.cpp -o simulator./simulatorThen enter the total memory size, followed by commands.
<memory_size>
Example:
1024
| Command | Syntax | Description |
|---|---|---|
| Request allocation | RQ <pid> <bytes> <strategy> |
Allocate <bytes> for numeric process ID <pid> using strategy B, W, or F. |
| Release allocation | RL <pid> |
Release the segment owned by process ID <pid>. |
| Compact | C |
Shift allocated segments toward address 0, creating one trailing hole. |
| Statistics | STAT |
Print all regions as start -> end : <pid or Hole>. |
| Exit | X |
Exit the simulator loop. |
- Best Fit (
B): picks the smallest hole that can satisfy the request - Worst Fit (
W): picks the largest available hole - First Fit (
F): picks the first hole in address order that fits
Simulator
1024
RQ 1 200 F
RQ 2 150 B
STAT
0 -> 199 : 1
200 -> 349 : 2
350 -> 1023 : Hole
RL 1
STAT
0 -> 199 : Hole
200 -> 349 : 2
350 -> 1023 : Hole
C
STAT
0 -> 149 : 2
150 -> 1023 : Hole
X
The simulator tracks memory using:
Segments(set<pair<ll,ll>>): allocated ranges{start, end}Segments_map(map<pair<ll,ll>, int>): range → PIDhole_pairs(set<pair<ll,ll>>): free ranges{start, end}(used by First Fit)hole_durations(set<pair<ll,ll>>): free ranges{duration, start}(used by Best/Worst Fit)
- Command parsing is minimal: unknown commands are typically ignored, non-numeric
RQfields can throwstd::stoullconversion errors, and incompleteRQ/RLcommands can cause crashes or other unexpected behavior. Use the exact command formats above. - Allocation/release/compaction operations are mostly silent; use
STATto inspect state.