Dr. Vesselin Bontchev wrote:
Hello folks,
My application enumerates all databases in the main memory of the device, using
a DmGetNextDatabaseByTypeCreator loop. Each database found is examined and, if
it meets certain criteria, is deleted.
Problem is, deleting (or creating, for that matter) a database screws up the
DmGetNextDatabaseByTypeCreator loop. There are two obvious solutions to this:
1) Collect the IDs of the databases that should be deleted and delete them
after the DmGetNextDatabaseByTypeCreator loop completes.
2) Restart the search loop every time a database is deleted.
Are there any more clever solutions to this? Fiddling with the DmSearchState
structure, perhaps? Or something else?
Regards,
Vesselin
Well, since during the deletion datbases can move, and the palm can
reshuffle internal pointers (not saying that it will, just saying that
it can), I think #1 is the best option of the two listed. I do have an
idea that /might/ work on current palms, I have not tested this. Its
based on the principle of delayed deletes ... let me explain :)
Psuedo code:
Get the first database
loop until out of databases
if current database meets criteria for deletion
DeleteDatase = this database // Delay the delete
Get the next database // Get the next database, still ok
since database is not gone
if DeleteDatabase not empty then
delete the database // Perform the delete now, since we
no longer need its pointers
end loop
This code will work if the Palm keeps its list of databases in a
structure resembling a linked list. I don't guarentee it, I have not
tested it, it is just an idea ...
Chris Olson
--
chris | Roleplayer, Palm PDA Programmer, Avid Reader, Husband, Wanna-
@pdaguy | be-Writer, Geek, Black Belt, Coder, Father of 2, Cycler, 6'5"
.com | Long, Red, Pony-tailed hair, Bearded, 235pd Teddy Bear
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/