Hardware Reference
In-Depth Information
memory words, the processes can now communicate with each other and pass data
back and forth at very high bandwidth, since no copying is required. Different
processes may have different access permissions. Since all the processes using a
mapped file share the same pages, changes made by one of them are immediately
visible to all the others, even if the disk file has not yet been updated.
The Win32 API contains a number of functions that allow a process to manage
its virtual memory explicitly. The most important of these functions are listed in
Fig. 6-34. All of them operate on a region consisting of either a single page or a
sequence of two or more pages that are consecutive in the virtual address space.
API function
Meaning
VirtualAlloc
Reserve or commit a region
VirtualFree
Release or decommit a region
VirtualProtect
Change the read/write/execute protection on a region
VirtualQuery
Inquire about the status of a region
VirtualLock
Make a region memory resident (i.e., disable paging for it)
VirtualUnlock
Make a region pageable in the usual way
CreateFileMapping
Create a file-mapping object and (optionally) assign it a name
MapViewOfFile
Map (part of) a file into the address space
UnmapViewOfFile
Remove a mapped file from the address space
OpenFileMapping
Open a previously created file-mapping object
Figure 6-34. The principal Windows 7 API calls for managing virtual memory
The first four API functions are self-explanatory. The next two give a process
the ability to hardwire some number of pages in memory so they will not be paged
out and to undo this property. A real-time program might need this ability, for ex-
ample. Only programs run on behalf of the system administrator may pin pages in
memory. And a limit is enforced by the operating system to prevent even these
processes from getting too greedy. Although not shown in Fig. 6-34, Windows 7
also has API functions to allow a process to access the virtual memory of a dif-
ferent process over which it has been given control (i.e., for which it has a handle).
The last four API functions listed are for managing memory-mapped files. To
map a file, a file-mapping object must first be created, with CreateFileMapping .
This function returns a handle to the file-mapping object and optionally enters a
name for it into the file system so another process can use it. The next two func-
tions map and unmap files, respectively. A mapped file is (part of) a disk file that
can be read from or written to just by accessing the virtual address space, with no
explicit I/O. The last one can be used by a process to map in a file currently also
mapped in by a different process. In this way, two or more processes can share re-
gions of their address spaces.
These API functions are the basic ones upon which the rest of the memory
management system is constructed. For example, there are API functions for
 
Search WWH ::




Custom Search