Accessing Files Programmer's Guide (32650-90885)

144 Chapter11
Accessing a File Using Mapped Access
Opening a File Mapped
access to large amounts of shared virtual memory. You can use the pointer as a large array
of any type to efficiently access the file.
A file created using the
long-mapped option
can be up to 4GB - 64KB in size. There is no
practical limit of the number of long-mapped access files that a process can have open at a
time.
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.
Advantages of long-mapped access over short-mapped access are:
You can access much larger files than you can using the
short-mapped option
.
You can open files that were opened previously with any options (as long as the
exclusive status of the file is not violated)
The disadvantage of long-mapped access is that it may be slower than short mapped access
because of the need to load a space register to access the long-pointer space. long-mapped
access can be as much as four times slower than short-mapped access, although
long-mapped access still can be faster than accessing the file through the file system data
transfer intrinsics.
The degradation can be minimized if you make the references to the long pointer space in a
localized part of your code. This way it may be possible for the system to keep the pointer
to the file's virtual space loaded into a space register rather than to repeatedly load and
unload it.
Large-mapped access
Item #87, large-mapped option is similar to the long-mapped option. However, due to the
possible issues of trying to dereference a data structure that straddles a space ID
boundary, the large-mapped option is required whenever opening a large file for user
mapped access. Specifying this option indicates that the programmer is aware of the issue
of cross-SID buffers and has coded the application to correctly handle this situation. In all
other respects the large-mapped option is identical to the long-mapped option.
Opening a File Mapped
Example 11-1 illustrates how a file is created and opened with short-mapped access. This
HP Pascal/XL program segment opens the file, then writes data to the file with
assignments to the array structure. The procedure then sets the EOF and closes the file.
The file is then reopened short-mapped, and data is retrieved before the file is closed and
purged.
Example 11-1. Opening a Mapped File
procedure Mapped_File_Example;
type
record_t = record {** defines an 80-byte record **}