Skip to content

About

This is a sample simulator for variable partition scheming in memory management.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Variable Partition Scheme Simulator

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.

Current Implementation Status

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
  • STAT prints memory ranges in ascending order as either allocated PID or Hole

Build

Compile both translation units:

g++ -std=c++11 -Wall -Wextra -pedantic main.cpp core/manager.cpp -o simulator

Run

./simulator

Then enter the total memory size, followed by commands.

Input Format

Initial line

<memory_size>

Example:

1024

Commands

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.

Strategies

  • 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

Example Session

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

Internal Data Structures

The simulator tracks memory using:

  • Segments (set<pair<ll,ll>>): allocated ranges {start, end}
  • Segments_map (map<pair<ll,ll>, int>): range → PID
  • hole_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)

Notes / Limitations

  • Command parsing is minimal: unknown commands are typically ignored, non-numeric RQ fields can throw std::stoull conversion errors, and incomplete RQ/RL commands can cause crashes or other unexpected behavior. Use the exact command formats above.
  • Allocation/release/compaction operations are mostly silent; use STAT to inspect state.

About

This is a sample simulator for variable partition scheming in memory management.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages