Accessing Files Programmer's Guide (32650-90885)

142 Chapter11
Accessing a File Using Mapped Access
How to Access a File Mapped
How to Access a File Mapped
You can access a file mapped by declaring a short (32-bit) or long (64-bit) pointer variable
within a program and passing that variable to the appropriate HPFOPEN option. The
HPFOPEN intrinsic returns the variable pointing to the beginning of the data area of the
opened file.
After HPFOPEN returns the address of the file, you simply reference the pointer as an array.
The machine architecture ensures integrity and protection of the file.
The following file types are allowed any type of access (Read, Write, Read/Write, and so
forth) when opened using mapped access options:
standard disk files with fixed-length or undefined-length record formats
The following file types are allowed read-only access when opened using mapped access
options:
standard disk files with variable-length record formats
KSAM files opened with
copy mode option
enabled
The following file types are not allowed to be opened using mapped access options:
relative I/O (RIO) files
message (MSG) files
circular (CIR) files
device files
You can use all applicable file system intrinsics with files opened for mapped access,
including all data transfer intrinsics; however, when mixing data transfer intrinsic calls
(such as FREAD and FWRITE) with mapped access, you must take into consideration the
data type (ASCII/binary) of the file, the record format, and the record size. Otherwise, data
written to the file using mapped access may not make sense when read by FREAD.
When you open a file using mapped access and write data to that file, you must use the
FPOINT and FCONTROL intrinsics to reset the EOF before you close the file. Otherwise, all
data you write to the file after the EOF will be lost when you close the file. In the case of a
newly created file, the EOF initially points to record zero.
NOTE
When you access a file with mapped access you are bypassing file system
services that set various file system pointers automatically, including the
EOF and the logical record pointer. You are responsible for resetting the EOF
prior to closing a file that you have accessed mapped. Also, file system posting
is bypassed; so, if data recovery is needed you should use FCONTROL
controlcodes
2 and/or 6 to post data and update the EOF periodically.
Heavy use of the FCONTROL intrinsic to post data and set the EOF degrades
performance due to the overhead of the extra posting.
When attempting to set the EOF to the file limit for a file opened with mapped access, the