However collectors for languages like c and c cannot

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: same semantics, except that it rejects requests to shrink the heap. The allocator itself is contained in a source file (malloc.c) that users can compile and link into their applications. The allocator exports three functions to application programs: 1 2 3 int mm_init(void); void *mm_malloc(size_t size); void mm_free(void *bp); 536 CHAPTER 10. VIRTUAL MEMORY code/vm/memlib.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 #include "csapp.h" /* private global variables */ static void *mem_start_brk; /* points to first byte of the heap */ static void *mem_brk; /* points to last byte of the heap */ static void *mem_max_addr; /* max virtual address for the heap */ /* * mem_init - initializes the memory system model */ void mem_init(int size) { mem_start_brk = (void *)Malloc(size); /* models available VM */ mem_brk = mem_start_brk; /* heap is initially empty */ mem_max_addr = mem_start_brk + size; /* max VM address for heap */ } /* * mem_sbrk - simple model of the the sbr...
View Full Document

Ask a homework question - tutors are online