Memory files and hiperspace memory files

You can use regular memory files on all the systems that z/OS® XL C/C++ supports. To create one, specify type=memory on the fopen() or freopen() call that creates the file. A memory file, once created, exists until either of the following happens:

While a memory file exists, you can just use another fopen() or freopen() that specifies the memory file's name. As sample program CCNGOF1 shows in Figure 1, you do not have to specify type=memory.

Figure 1. Memory file example
/* this example shows how fopen() may be used with memory files */

#include <stdio.h>
char text[3], *result;
FILE * fp;

int main(void)
   {
   fp = fopen("a.b", "w, type=memory");  /* Opens a memory file */
   fprintf(fp, "%d\n",10);               /* Writes to the file  */
   fclose(fp);                           /* Closes the file     */
   fp = fopen("a.b", "r");               /* Reopens the same    */
                                         /*  file (already      */
                                         /*  a memory file)     */
   if ((result=fgets(text,3,fp)) !=NULL) /* Retrieves results   */
      printf("value retrieved is %s\n",result);
   fclose(fp);                           /* Closes the file     */

   return(0);
   }

A valid memory file name will match current file restrictions on a real file. Thus, a memory file name that is classified as UNIX file system can have more characters than can one classified as an MVS™ file name.

If you are not running under CICS, you can open a Hiperspace memory file as follows:
   fp = fopen("a.b", "w, type=memory(hiperspace)");

If you specify hiperspace and you are running in a CICS environment, z/OS XL C/C++ opens a regular memory file. If you are running with the runtime options POSIX(ON) and TRAP(OFF), specifying hiperspace has no effect; z/OS XL C/C++ will open a regular memory file. You must specify TRAP(ON) to be able to create Hiperspace files.

Restriction: Hiperspace is not supported in AMODE 64 applications. If you specify hiperspace in AMODE 64 applications, z/OS XL C/C++ opens a regular memory file.