|
|
Accessing Files Programmer's Guide: HP 3000 MPE/iX Computer Systems > Chapter 11 Accessing a File Using Mapped AccessHow 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:
The following file types are allowed read-only access when opened using mapped access options:
The following file types are not allowed to be opened using mapped access options:
You can use all applicable file system intrinsics 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.
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.
There are two perspectives you can take on mapped file 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. Item #21 long-mapped option is available in the HPFOPEN intrinsic to provide you with 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 two gigabytes 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:
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. |
|