This preview shows page 1. Sign up to view the full content.
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 ﬁle to stdout. The name of the input ﬁle 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
- Spring '10
- The American