next up previous contents Back To Software Index
Next: Piped FITS Files Up: Disk FilesMemory-Resident Previous: Disk FilesMemory-Resident

Reading or Writing Memory-Resident FITS Files

CFITSIO can read and write FITS 'files' in a block of core computer memory, in shared memory, or memory-mapped disk files. Most of the CFITSIO routines operate on these files in exactly the same way as for FITS files on disk, with the only difference being that one must first call an additional routine before opening or creating the FITS file to tell CFITSIO that it will reside in memory and not on disk. This routine is called 'fits_set_mem_buff' and is described in detail in section 7.1. This routine is used to tell CFITSIO the initial address and size of the block of memory that will be used for the FITS file, and, optionally, to supply a function that CFITSIO can call to allocate more memory if necessary. Since access to these memory-resident files can be much faster than for magnetic disk files, this feature of CFITSIO can be used to reduce the I/O processing times when dealing with FITS files as long as the machine has enough memory to hold the entire file.

When a CFITSIO routine writes to a FITS file in memory, it initially writes to one of a set of internally cached memory buffers that are used to improve the I/O efficiency when dealing with disk files, and not directly to the memory file. Consequently, the application program must either close the FITS file or call the fits_flush_file routine to flush the cached buffers out to the memory FITS file.

When the FITS file is closed, CFITSIO does not free or deallocate the memory buffer. The application program may still access the memory file, for example, by copying it to a disk file (with fits_write_mem_buff) or by re-opening it again with CFITSIO. The application program is responsibility for freeing the memory once it is no longer needed.

A test program called `testmem.c' is included in this distribution which illustrates the use of this feature to write and then read back a test FITS file in memory. This program also calls fits_write_mem_buff to copy the memory file out to a disk file called 'testmem.fit'.



next up previous contents Back To Software Index
Next: Piped FITS Files Up: Disk FilesMemory-Resident Previous: Disk FilesMemory-Resident