2 a using the rst t algorithm on a free list that is

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: the block sizes are known in advance to be powers of two, buddy system allocators have a certain appeal. 10.10 Garbage Collection With an explicit allocator such as the C malloc package, an application allocates and frees heap blocks by making calls to malloc and free. It is the application’s responsibility to free any allocated blocks that it no longer needs. 10.10. GARBAGE COLLECTION 547 Failing to free allocated blocks is a common programming error. For example, consider the following C function that allocates a block of temporary storage as part of its processing. 1 2 3 4 5 6 void garbage() { int *p = (int *)Malloc(15213); return; /* array p is garbage at this point */ } Since p is no longer needed by the program, it should have been freed before foo returned. Unfortunately, the programmer has forgotten to free the block. It remains allocated for the lifetime of the program, needlessly occupying heap space that could be used to satisfy subsequent allocation requests. A garbage collector is a dynamic storage allocator that autom...
View Full Document

Ask a homework question - tutors are online