Wikipedia
This program allows 64 blocks to be allocated and deallocated, and it correctly merges freed blocks. Each time the program splits a block, it adds a ’|’ to show where the split happened. ’-’ represents free blocks, and ’#’ represents in-use blocks. The two numbers printed out as in 0/4 represent the beginning address and number of blocks in a chunk. The program takes three one-letter commands: ’a’ for allocate, ’f’ for free, and ’q’ for quit. The second argument on a line is the number of blocks (for allocate) or the address, or first block number, of the allocated chunk (for free).
Use Python to run buddy-memory-allocator.py.
python buddy-memory-allocator.py# 'a' for allocation / numebr of blocks
a 4
# 'f' foor free / the beginning address
f 0
# 'q' for quit
q