At 1:00 PM +0800 11/20/01, chakin1 wrote:
>Hi guys/gals,
>
>My application will initialize the database at the application start
>routine. However when I exit the application and go back in again, the
>database is corrupted. I have closed the database when the application is
>quitted. Why is it so? Please help.
Chakin1,
First of all, please let me help you write a better question. The
question you provided is too sparse on details. We don't know what
you're writing to your database, how you're writing it, why you think
you're writing it correctly, or why you think it's corrupted.
In order to learn how to ask better questions, you might want to see:
<http://www.tuxedo.org/~esr/faqs/smart-questions.html>
That aside, I could take a guess and say that you are writing records
to the database that contain pointers to heap based data. E.g.:
struct MyDatabaseRecord
{
int someInteger;
char* someSting;
};
If you wrote this to your database, and "someString" was some data
you allocated with MemPtrNew or something like that, then you might
find your database in a state one could call "corrupted". That's
because the string data is not written to the database. Only the
pointer to the string is. Once your application quits, the OS will
reclaim all data you left lying around, including the string data.
If this scenario describes your situation, then you need to take a
different approach to saving your data. For instance, you might want
to measure your string with StrLen, allocate a database record large
enough for it (along with its terminating NULL) and all other record
data, and write the data to the record piecemeal with DmWrite.
HTH,
--
For information on using the Palm Developer Forums, or to unsubscribe, please see
http://www.palmos.com/dev/tech/support/forums/