Also some areas of virtual memory are read only

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: 6 7 8 9 10 11 12 13 14 15 16 17 18 static void *extend_heap(size_t words) { char *bp; size_t size; /* Allocate an even number of words to maintain alignment */ size = (words % 2) ? (words+1) * WSIZE : words * WSIZE; if ((int)(bp = mem_sbrk(size)) < 0) return NULL; /* Initialize free block PUT(HDRP(bp), PACK(size, PUT(FTRP(bp), PACK(size, PUT(HDRP(NEXT_BLKP(bp)), header/footer and the epilogue header */ 0)); /* free block header */ 0)); /* free block footer */ PACK(0, 1)); /* new epilogue header */ /* Coalesce if the previous block was free */ return coalesce(bp); } code/vm/malloc.c Figure 10.47: extend heap: Extends the heap with a new free block. Freeing and Coalescing Blocks An application frees a previously allocated block by calling the mm free function (Figure 10.48), which frees the requested block (bp), and then merges adjacent free blocks using the boundary-tags coalescing technique described in Section 10.9.11. The code in the coalesce helper function is a straightforward implementation of the four cases outlined in Figure 10.42. There is one somewhat subtle aspect. The free li...
View Full Document

Ask a homework question - tutors are online