Accessing Files Programmer's Guide (32650-90885)

Chapter 11 143
Accessing a File Using Mapped Access
How to Access a File Mapped
FCLOSE intrinsic disposition parameter, bit 10:1 set to 1 will force the EOF to the file
limit. This overcomes the problem of trying to FPOINT to the file limit.
Advantages of mapped access
Mapped access to a file can be much faster than access through normal file system
intrinsics. This is especially the case when you are accessing a smaller file randomly
rather than sequentially. When accessing a file mapped, there is no file system overhead
associated with a specific reference to the file. The only difference between accessing a file
mapped and accessing normal memory is the locality of the access and the protection
strategy.
NOTE
It is possible to show a degradation of performance if an application that
accesses files sequentially is modified to access those files mapped. Normal
system reads prefetch multiple records per read. Mapped file access has no
method of prefetching the data, consequently, some performance penalty is
paid by additional overhead on page faults.
There are two perspectives you can take on mapped file access:
1. A file is accessible as virtual memory. The advantages from this perspective are high
performance and fast response time from the file system.
2. Virtual memory is accessed through the file system. The advantages from this
perspective are
Virtual memory can be easily saved permanently.
Virtual memory can be checkpointed.
Virtual memory can be easily shared through a common naming convention.
Short-mapped access
Item #18
short-mapped option
is available in the HPFOPEN intrinsic to provide you with
shared virtual memory. A short pointer is returned in an optional
item
parameter. You can
use the pointer as a large array of any type to efficiently access the file.
A file created using the
short-mapped option
can be up to four megabytes in size. A
process can have open at the same time up to six megabytes of files that are opened using
the
short-mapped option
. For larger file needs, a file created using the
long-mapped
option
is required.
An error results if you attempt to open a file using the
short-mapped option
that you
have previously opened normally or with the
long-mapped option
.
You cannot access a loaded program file or a loaded library file using either mapped access
option. In addition, you cannot load a file that is currently being accessed mapped.
Long-mapped access
Item #21
long-mapped option
is available in the HPFOPEN intrinsic to provide you with