This preview shows page 1. Sign up to view the full content.
Unformatted text preview: ces: (1) when the heap is initialized, and (2) when mm malloc is unable to ﬁnd a suitable ﬁt. To maintain alignment, extend heap rounds up the requested size to the nearest multiple of 2 words (8 bytes), and then requests the additional heap space from the memory system (lines 7–9). The remainder of the extend heap function (lines 12–17) is somewhat subtle. The heap begins on a double-word aligned boundary, and every call to extend heap returns a block whose size is an integral number of double-words. Thus, every call to mem sbrk returns a double-word aligned chunk of memory immediately following the header of the epilogue block. This header becomes the header of the new free block (line 12), and the last word of the chunk becomes the new epilogue block header (line 14). Finally, in the likely case that the previous heap was terminated by a free block, we call the coalesce function to merge the two free blocks and return the block pointer of the merged blocks (line 17). 540 CHAPTER 10. VIRTUAL MEMORY
code/vm/malloc.c 1 2 3 4 5...
View Full Document