I have written a set of functions that allow a program to access a Read-Only 
database, whether it's in RAM or on a card. The functions are all similiar 
to the standard Palm Database Manager functions. The beauty of this is that 
the database is NOT copied as a whole to RAM, just the resources or records 
that you need. After you use a resource or Record, its cache is kept in RAM 
for even quicker access later, untill database is closed.
This is very useful for programs which have a large amount of Read-Only 
data, which the users usually like to keep on a Card. The problem is that 
the Palm Launcher copies the whole file first to RAM, which causes a 
signifigant delay for launch. And sometimes the copy may fail due to lack of 
memory. Also, many programs must be installed in RAM.
With our virtual method, the developer creates two databases, the main one 
should preferably be in RAM, while the secondary can be moved to the card. 
There is very little delay, because little is copied. The only change the 
developer must do, is to open the secondary Virtual Database on program 
launch, close it when program exits, and use the Vm (Virtual Manager) 
functions, instead of the Dm (Database Manager) functions.
The code is NOT fully tested, and I would appreciate developer input.
Please let me know of any suggested changes or bugs. Any contact or reply 
would be appreciated.
The code is free to use or change, as per notice on top of the source file.
You can download the code, including a test program from 
http://www.lionscribe.com/downloads/vmdatamgr.zip
You can also download my template for creating a Multi-Segment Shared 
library (with debugging) at 
http://www.lionscribe.com/downloads/multisegsharedlib.zip

LionScribe

Here is a short copy of the header file

// VmOpenRef - the replacement for DmOpenRef
typedef void* VmOpenRef;

// VmOpenDatabase - Use similiarly to DmOpenDatabase.
 // Uses the database name  instead of LocalID.
 // For mode, the only used value in mode is (dmModeReadOnly) and 
(dmModeReadOnly | dmModeShowSecret)
VmOpenRef VmOpenDatabase (char * nameP, Boolean resDB, UInt16 mode);
Err VmCloseDatabase(VmOpenRef vdbrP);

UInt16 VmFindResourceType(VmOpenRef vdbrP, DmResType resType, UInt16 
typeIndex);
UInt16 VmFindResource(VmOpenRef vdbrP, DmResType resType, DmResID resID, 
MemHandle resH);
MemHandle VmGetResource(DmResType type, DmResID resID);
MemHandle VmGet1Resource(DmResType type, DmResID resID);
Err VmReleaseResource(MemHandle resourceH);
MemHandle VmGetResourceIndex(VmOpenRef vdbrP, UInt16 index);
UInt16 VmNumResources(VmOpenRef vdbrP);
Err VmDatabaseInfo(VmOpenRef vdbrP, Char *nameP, UInt16 *attributesP, UInt16 
*versionP, UInt32 *crDateP,  UInt32 * modDateP, UInt32 *bckUpDateP,  UInt32 
* modNumP, LocalID *appInfoIDP,  LocalID *sortInfoIDP, UInt32 *typeP, UInt32 
*creatorP);
Err VmResourceInfo(VmOpenRef vdbrP, UInt16 index, DmResType *resTypeP, 
DmResID *resIDP, LocalID *chunkLocalIDP);

UInt16 VmNumRecords(VmOpenRef vdbrP);
UInt16 VmNumRecordsInCategory(VmOpenRef vdbrP, UInt16 category);
MemHandle VmQueryRecord(VmOpenRef vdbrP, UInt16 index);
MemHandle VmQueryNextInCategory(VmOpenRef vdbrP, UInt16 *indexP, UInt16 
category);
Err VmSeekRecordInCategory (VmOpenRef vdbrP, UInt16 *indexP, UInt16 offset, 
Int16 direction, UInt16 category);
UInt16 VmPositionInCategory (VmOpenRef vdbrP, UInt16 index, UInt16 
category);
Err  VmRecordInfo(VmOpenRef vdbrP, UInt16 index, UInt16 *attrP, UInt32 
*uniqueIDP, LocalID *chunkIDP);
Err  VmFindRecordByID(VmOpenRef vdbrP, UInt32 uniqueID, UInt16 *indexP);

UInt16 VmSearchResource(DmResType resType, DmResID resID, MemHandle resH, 
DmOpenRef *dbPP);
UInt16 VmSearchRecord(MemHandle recH, DmOpenRef *dbPP);

// VmPrepareResource - VmPrepareResourceType
 //  Only needed for when you use a resource without calling VmGetResource 
or the like.
 //  Usually needed for a system type resource, like a Form or Alert, before 
calling FrmInitForm or the like.
UInt16 VmPrepareResource(VmOpenRef vdbrP, DmResType resType, DmResID resID);
void VmPrepareResourceType(VmOpenRef vdbrP, DmResType resType);

// VmFreeResource - VmFreeRecord
 //  Do not have to be called. Call only if you want to manualy release the 
memory cache of a resource or a record.
 // If not called, then the memory is freed when you call VmClodeDatabase
 // Use when memory might be short, or when going through all records like 
by a search
 //  Try calling this function on the lase record that was opened (LIFO), 
for quickest results.
void VmFreeResource(VmOpenRef vdbrP, DmResType resType, DmResID resID);
void VmFreeRecord(VmOpenRef vdbrP, UInt16 index);

// VmDatabaseOnCard
//  Returns true if Virtual Database is in Card, False if it's in RAM
Boolean VmDatabaseOnCard(VmOpenRef vdbrP);



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please 
see http://www.palmos.com/dev/support/forums/

Reply via email to