Marking Techniques
. Suspend execution of the user program
. use frozen pointers to determine which blocks are in use
. This approach requires knowledge of all the pointers
. Go through the heap marking all the blocks unused
. Then follow pointers marking a block as used that is reachable
. De-allocate a block still marked unused
. Compaction: move all used blocks to the end of heap. All the pointers must be adjusted to reflect the move
Marking techniques can be seen as first freezing all activity, and then using an algorithm where you first 'color' all nodes as unused. Then at each pointer, you 'drop down' the color 'used' through links, and all nodes which are colored by this color become marked as 'used'. After this , if a node remains marked as 'unused', then it is truly unused, and can be discarded as garbage.
Compaction can be used to save space, but it takes a lot of time as when a block is moved in memory, all pointers pointing to it have to be changed to point to the new location. This also requires us to keep track of all the pointers. The need for compaction is a major problem with variable-sized allotment.
|