Memory allocator: leftmost free block and free by owner
A memory has n units, numbered 0 to n - 1, all free at the start. Process a list of operations in order, each producing one recorded value:
- Allocate
sizeunits for anowner: find the leftmost run ofsizeconsecutive free units, give all of them to the owner and record the run's first index, or record-1if no run is long enough. - Free by owner: release every unit the owner holds and record how many units were freed.
Return the recorded values. Start with a direct simulation, then discuss how to make allocation faster when the memory is large.
No answer yet. Write the first one; the best answer gets endorsed.
