Introduction to file‑stack processing

A file stack is multiple sets of fixed‑length, logical records, stored in a single, physical scratch file. These logical record sets are organized in the file in a last‑in, first‑out (LIFO) stack manner.

Why use file stacks?

Let’s say that your application does some processing that requires the use of a temporary file. For instance, it might present the user with a list of choices and record each one selected into a temporary file. However, the user might use a hot entry to pop up a different function, also using a temporary file. Traditionally, you had to open a separate temporary file for the second process. Instead, you would like to extend your already‑opened temporary file for use by the hot‑entry process, and then cut back to your original use of the file when the hot‑entry process returns.

When you use a file stack, you have several advantages over creating and maintaining your own temporary files:

How file stacks work

The file stack enables you to “stack” temporary files in one file. Each temporary file, also called a logical file, may have a different record length. As the logical files are stacked, the one most recently stacked becomes the “current” file. When that one is closed, the file that was stacked immediately prior to it becomes the current file.

Only the current file can be extended. If you need to extend more than one logical file at a time, you can initiate multiple file stacks. For example, in the distributed version of the list‑processing routines, each list has its own private file stack. Typically, processing occurs on the current file, which is also the current level, though you may read from and write to records on any level.

How much memory do the file stacks allocate?

The amount of memory allocated by the file stack will be the largest among the following:

Any value specified is rounded up to the nearest multiple of 16,384 but not more than 114,688. Note, however, that file stack processing caches data so that data is saved to disk only if the size of the cache (which is just over 100K) is exceeded.