Creating a View Within a File

If you want to view a portion of the file that does not start at the beginning of the file, you must create a
file mapping object. This object is the size of the portion of the file you want to view plus the offset into the
file. For example, if you want to view the 1 kilobyte (1K) that begins 131,072 bytes (128K) into the file, you
must create a file mapping object of at least 132,096 bytes (129K) in size. The view starts 131,072 bytes
(128K) into the file and extend for at least 1,024 bytes. This example assumes a file allocation granularity of 64K.

File allocation granularity affects where a map view can start. A map view must start at an offset into the file
that is a multiple of the file allocation granularity. So the data you want to view may be the file offset
modulo the allocation granularity into the view. The size of the view is the offset of the data modulo the
allocation granularity, plus the size of the data that you want to examine.

For example, suppose that the
GetSystemInfo function indicates an allocation
granularity of 64K. To examine 1K of data that is 138,240 bytes (135K) into the file, do the following:

Create a file mapping object of at least 139,264 bytes (136K) in size.

Create a file view that starts at a file offset that is the largest multiple of the file allocation granularity
less than the offset you require. In this case, the file view starts at offset 131,072 (128K) into the
file. The view is 139264 bytes (136K) minus 131,072 bytes (128K), or 8,192 bytes (8K), in size.

Create a pointer offset 7K into the view to access the 1K in which you are interested.

If the data you want straddles a file allocation granularity boundary, you could make the view larger than the
file allocation granularity. This avoids breaking the data into pieces.