Below is a sample program that will simulate how memory is managed by the computer's operating system:
Memory Manager Algorithms:
How to Use Memory Manager
STEP 1: Select memory manager algorithm (First Fit, Best Fit, or Worst Fit)
STEP 2: Enter the Total Memory in kilobytes (KB)
STEP 3: Enter the Memory used by the OS in kilobytes (KB)
STEP 4: Select a Program/Process (available P1 to P8)
STEP 5: Enter the Process Memory Size in kilobytes (KB)
STEP 6: Click "Add to Memory" to Update Chart.
* NOTE *: You can also select a Process and Remove from Memory.
* NOTE *: Select "Compact Memory NOW" to readjust the existing processes in memory and free up some RAM!
- There may be many holes in the memory, so the operating system, to reduce the amount of time it spends analyzing the available spaces, begins at the start of primary memory and allocates memory from the first hole it encounters large enough to satisfy the request. Using the same example as above, first fit will allocate 12KB of the 14KB block to the process.
- The allocator places a process in the smallest block of unallocated memory in which it will fit. For example, suppose a process requests 12KB of memory and the memory manager currently has a list of unallocated blocks of 6KB, 14KB, 19KB, 11KB, and 13KB blocks. The best-fit strategy will allocate 12KB of the 13KB block to the process.
- The memory manager places a process in the largest block of unallocated memory available. The idea is that this placement will create the largest hold after the allocations, thus increasing the possibility that, compared to best fit, another process can use the remaining space. Using the same example as above, worst fit will allocate 12KB of the 19KB block to the process, leaving a 7KB block for future use.
Also visit our article on how a operating system schedules processes.