Copyright ©1995 by NeXT Computer, Inc.  All Rights Reserved.

IXStoreFile



Inherits From: IXStore : Object
Declared In: store/IXStoreFile.h



Class Description

IXStoreFile is a subclass of IXStore that keeps its storage in a file.  Since a file can outlive processes, IXStoreFile can store persistent data.  IXStoreFile also guarantees the integrity of stored data against process and system crashes when protected by transactions, provided that the physical media remains intact.

IXStoreFile can open files for reading and writing, or for reading only, and it locks them with the flock() UNIX system call for exclusive or shared access, accordingly.  This locking is advisory only, but effectively prevents cache conflict between instances residing in separate processes on the same host.  Note, however, that the advisory locks aren't visible over the network, due to limitations of flock(); responsibility for managing cache conflicts when sharing files over the network falls to the program using the IXStoreFile.  The suggested approach is to build a server with NEXTSTEP Distributed Objects that mediates access to files among client processes.

To support the use of preconfigured files, an IXStoreFile opened for reading only may be modified freely by the process using it; all modified pages are reflected only in the address space of that process.  The modifications are never written to the file, and are discarded when the IXStoreFile is freed.

IXStoreFile is extremely efficient with respect to paging.  When pages would be forced from memory by the virtual memory system, IXStoreFile writes them directly back to the storage file instead of allowing them to go through the swap file.  The transaction management architecture takes advantage of this, ensuring the minimum number of page faults per transaction.

Warning: This write-back mapping isn't currently supported by vm_copy().  If you use this function to copy into an IXStoreFile, you risk causing your application to hang or crash.  If your code doesn't guarantee the actual class of a store, be sure to check it (using isMemberOf: instead of isKindOf:) before writing into a block with vm_copy().
Portability Issues
The Indexing Kit's higher-level components expect all data in a storage file to be big-endian, so you should always use the NXSwapBigTypeToHost() function when reading data in an IXStoreFile, and the NXSwapHostTypeToBig() function when writing data.
See /NextLibrary/Documentation/NextDev/Concepts/PortabilityGuide.rtf for more information.



Instance Variables

int descriptor;

const char *filename;

struct {
unsigned int needsClose:1;
unsigned int isCreating:1;

} fileStatus;


descriptor The file descriptor for the storage file.
filename The name of the storage file.
fileStatus.needsClose True if the storage file was opened by this IXStoreFile.
fileStatus.isCreating True if the storage file was created by this IXStoreFile.



Method Types

Initializing and freeing instances init
initWithFile:
initFromFile:forWriting:
free
Limiting the file mapping size setSizeLimit:
sizeLimit
Getting file information descriptor
filename



Instance Methods

descriptor
(int)descriptor

Returns the file descriptor for the IXStoreFile's storage file.

See also:  filename



filename
(const char *)filename

Returns the name of the IXStoreFile's storage file.

See also:  descriptor



free
free

Unlocks and closes the storage file and frees the IXStoreFile.  The file isn't removed from the file system, even if it was a temporary file created by the init method.  Returns nil.

This method aborts any pending modifications.  Your code should always send commitTransaction until the transaction nesting level is 0 before closing an IXStoreFile in order to save any outstanding changes.

See also:  init, commitTransaction (IXStore), abortTransaction (IXStore)



init
init

Initializes the IXStoreFile with a temporary file (created in /tmp) that's opened for writing.  Returns self.

See also:  initWithFile:, initFromFile:forWriting:



initFromFile:forWriting:
initFromFile:(const char *)filename forWriting:(BOOL)flag

Initializes the IXStoreFile from the previously created filenamefilename must have been previously created by the initWithFile: method.  If flag is YES, then filename is opened for reading and writing, and locked for exclusive access.  If flag is NO, then filename is opened for reading only, and locked for shared access. If filename is opened for reading only, any changes made to the IXStoreFile will be reflected only memory, and will never be flushed to disk. This is the designated initializer for IXStoreFile objects that use an existing storage file.  Returns self.

See also:  initWithFile:



initWithFile:
initWithFile:(const char *)filename

Initializes the IXStoreFile with filename as its storage file.  filename is created and opened for reading and writing, and locked for exclusive access.  This the designated initializer for the IXStoreFile class.  Returns self.

See also:  init, initFromFile:forWriting:



setSizeLimit:
setSizeLimit:(vm_size_t)aLimit

Limits the amount of virtual address space consumed by file mapping to aLimit. If aLimit is zero, the size limit is removed.  The size limit determines how much of the file the IXStoreFile will try to cache in main memory.  Given enough memory, the higher the size limit, the better the performance.  If your code will be operating on a machine with little memory, you should set the limit to a relatively small number; for example, 128KB on an 8-megabyte machine.  Returns self.

See also:  sizeLimit



sizeLimit
(vm_size_t)sizeLimit

Returns the maximum amount of virtual address space consumed by file mapping.  The size limit determines how much of the file the IXStoreFile will try to cache in main memory.  Given enough memory, the higher the size limit, the better the performance.

See also:  setSizeLimit: