For example figure 1040 shows the result of freeing

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: le, bufp = Mmap(NULL, size, PROT_READ, MAP_PRIVATE|MAP_ANON, 0, 0); asks the kernel to create a new read-only, private, demand-zero area of virtual memory containing size bytes. If the call is successful, then bufp contains the address of the new area. The munmap function deletes regions of virtual memory. #include <unistd.h> #include <sys/mman.h> int munmap(void *start, size t length); returns: 0 if OK, -1 on error The munmap function deletes the area starting at virtual address start and consisting of the next length bytes. Subsequent references to the deleted region result in segmentation faults. 522 Practice Problem 10.5: CHAPTER 10. VIRTUAL MEMORY Write a C program mmapcopy.c that uses mmap to copy an arbitrary-sized disk file to stdout. The name of the input file should be passed as a command line argument. 10.9 Dynamic Memory Allocation While it is certainly possible to use the low-level mmap and munmap functions to create and delete areas of virtual memory, most C programs use a dynamic memory allocator when they need to acquire additional virtual memory at run time. A dynamic...
View Full Document

Ask a homework question - tutors are online