My app works with a 2 MB PDB.  I'd like to move this PDB to a VFS volume for customers 
that don't have lots of free memory on their devices.  

Reading records from a card-based PDB is accomplished easily with 
VFSFileDBGetRecord().  However my PDB needs to be updated and written to, as well.  
There exist no APIs for writing to a PDB stored on a VFS volume, so it looks like I 
have to do it myself.  First, I want to ask if there are any code snipits, class 
libraries, or tools already developed that would make this a little less painful -- 
otherwise I'll start by grokking the DataMgr.c code for ideas.  David Fedor hints at 
something promising in this message, but the damned knowledgebase link is broken:

http://news.palmos.com/read/messages?id=79909#79909

Second, I'd be curious to hear input on my ideas.  Let's say "MyPDB" is a 2 MB file in 
PDB format stored on an SD card.  The PDB it represents contains 1000 patient record 
that are sorted by patient's last name.  In PDB format, the sort order is maintained 
in an index in the PDB header, so that the records can physically occupy any order.

I've come up with some thoughts about working with PDBs, but they entail leaving gaps 
of unreclaimed bytes between records that aren't immediately reclaimed, and I'm not 
sure if this will 'break' the PDB in the eyes of the DataMgr.

Task: A new patient record needs to be added to MyPDB.

1) See if there is enough space in the PDB header to add another record entry to it.  
If not, make room to grow the PDB header by moving the physically-first record(s) data 
in the PDB to the end of the file and update the PDB header accordingly.  Pad any 
unused space between end of just-grown PDB header block and new physically-first 
record with NULL.

2) Append the new record to the end of the file

3) Update the PDB header to point to this new record, in sorted order.

Task:  An existing record in MyPDB needs to be updated; it may grow, shrink, or stay 
the same size.
1) If it stays the same size, simply seek to its data in the file and update.  Update 
sort order in PDB header as necessary.  Done.

2) If it shrinks, I'm hoping i can get away with just writing in the smaller record, 
without reclaiming the that is opened up before the beginning of the next-adjacent 
record.  I'm not sure if this will work, because the size of this record may 
subsequently be misreported by DataMgr.  Such gaps would be reclaimed en masse at a 
later time.

3) If it grows, just move it to the end of the file and update the record header.  
This leaves a gap of space that needs to be reclaimed at a later time.

"at a later time" can be either when all updates/adds are done for any given database; 
or, at the user's option ("compress databases to reclaim space").

What do you think?

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

Reply via email to