Product Documentation

FairCom ISAM for C

Previous Topic

Next Topic

Sharing Memory Files Created Programmatically

There is a subtle issue about how to get a memory-resident file to be a shared file. At create, it is exclusive. If it is created and immediately closed, to be reopened for shared access, it would disappear on the close, and the reopen would fail. You can use the UpdateFileMode() c-tree API function to change the file mode from exclusive to shared:

CreateIFileXtd8(...);

UpdateFileMode(datno,ctSHARED);

UpdateFileMode(keyno_1,ctSHARED);

...

UpdateFileMode(keyno_n,ctSHARED);

The UpdateFileMode() call will fail if there are transaction-dependent actions pending. For example, if the CreateIFileXtd8() call in the above pseudo code were for a transaction-dependent (ctTRANDEP) file, the UpdateFileMode() call could not be called until the create is committed.

As noted above, the final close of a memory file causes all the existing memory file contents (data records or index nodes) to be lost. A final close refers to a file close that causes the user count of the file to drop to zero. It is possible to make the data file persist even after the final close by including ctKEEPOPEN bit in the splval member of the data file’s XCREblk. Then the final close leaves the file open (but without any user attached to the file.) It can then be opened again, and the data still exists. The file will be closed when the server terminates, or when a call is made to the CloseCtFileByName() c-tree API function:

CloseCtFileByName(pTEXT filnam,pTEXT fileword)

It is possible to use the ctKEEPOPEN flag on the create, and then close and reopen the file shared (without calling UpdateFileMode()), but only if the file’s creation is not pending commit. In this case, the sequence would be like:

XCREblk xcreblk[] = {

{ctMEMFILE, 0, 0, 104857600, 0,0,0,0,0,0, ctKEEPOPEN, 0,0,0,0,0},

{ctMEMFILE, 0, 0, 104857600, 0,0,0,0,0,0, ctKEEPOPEN, 0,0,0,0,0}

};

...

if (CreateIFileXtd8(&vcustomer,NULL,NULL,0,NULL,NULL,xcreblk))

{

ctrt_printf("\nCould not create file %d with error %d.\n",

isam_fil,isam_err);

}

else

{

CloseIFile(&vcustomer);

if ((eRet = OpenIFileXtd(&vcustomer,NULL,NULL,NULL)) != 0)

{

ctrt_printf("\nUNEXPECTED ERROR %d ON REOPEN.\n",eRet);

}

else

{

ctrt_printf("\nFile created in memory.");

}

}

TOCIndex