Hello,

I'm working on porting one of my company's applications to work on the Tungsten 
T5, and I think that I'm running out of DB Cache memory.  My app crashes with 
the following error:

DataMgr.c, Line: 11231,
Index out of range

I have log statements that report the free DB Cache memory, and they report 
that the memory gets down to ~24K before crashing.

Here's the code I'm using to calculate the amount of free DB Cache:

UInt16 nStorageHeapId = 1;
UInt32 nMax = 0;
UInt32 nFree = 0;
MemHeapFreeBytes(nStorageHeapId | dbCacheFlag, &nFree, &nMax);

I have tried two methods to free up DB Cache memory:

1)  Call DmSyncDatabase
2)  Call DmCloseDatabase, then call DmOpenDatabase.

I have written test code that validates the behavior I'm seeing (that these two 
methods do not free up DB Cache memory)

char msg[1024];
UInt16 size = 4444;
UInt8* buf = (UInt8*) MemPtrNew(size);
for (int i=0;i<size;i++)
        buf[i] = i;
                
char dbName[1024];
                
LocalID localId;
DmOpenRef dbRef;
UInt32 id;
UInt32 freeDBCache = DBCacheCalculateAvailable(); // Calls code listed above    

StrPrintF(msg, "Start Free DB Cache: %lu", freeDBCache);
ErrAlertCustom(0,msg,0,0);
                
StrPrintF(dbName, "TestDB");
                
localId = DmFindDatabase(0,dbName);
if (localId)
        DmDeleteDatabase(0,localId);
                        
DmCreateDatabase(0,dbName,'TEST','DATA',0);
                
freeDBCache = DBCacheCalculateAvailable();      
StrPrintF(msg, "CreateDB Free DB Cache: %lu", freeDBCache);
ErrAlertCustom(0,msg,0,0);
                
id = DmFindDatabase(0, dbName);
if (id > 0)
        dbRef = DmOpenDatabase(0,id,dmModeReadWrite);
                        
freeDBCache = DBCacheCalculateAvailable();      
StrPrintF(msg, "OpenDB Free DB Cache: %lu", freeDBCache);
ErrAlertCustom(0,msg,0,0);
                        
DmNewRecord(dbRef,0,size);
DmReleaseRecord(dbRef,0,true);
                
freeDBCache = DBCacheCalculateAvailable();      
StrPrintF(msg, "CreateRecord Free DB Cache: %lu", freeDBCache);
ErrAlertCustom(0,msg,0,0);
                
MemHandle memHandle = DmGetRecord(dbRef, 0);
if (memHandle)
{
        char* dest = (char*)MemHandleLock(memHandle);
        DmWrite(dest,0,buf,size);
        MemHandleUnlock(memHandle);
        DmReleaseRecord(dbRef,0,true);
}
                
freeDBCache = DBCacheCalculateAvailable();      
StrPrintF(msg, "WriteRecord Free DB Cache: %lu", freeDBCache);
ErrAlertCustom(0,msg,0,0);
                
DmSyncDatabase(dbRef);
        
freeDBCache = DBCacheCalculateAvailable();      
StrPrintF(msg, "SyncDB Free DB Cache: %lu", freeDBCache);
ErrAlertCustom(0,msg,0,0);
                
DmCloseDatabase(dbRef);
                
freeDBCache = DBCacheCalculateAvailable();      
StrPrintF(msg, "CloseDB Free DB Cache: %lu", freeDBCache);
ErrAlertCustom(0,msg,0,0);
                
localId = DmFindDatabase(0, dbName);
if (localId > 0)
        dbRef = DmOpenDatabase(0,localId,dmModeReadWrite);
                
freeDBCache = DBCacheCalculateAvailable();      
StrPrintF(msg, "OpenDB Free DB Cache: %lu", freeDBCache);
ErrAlertCustom(0,msg,0,0);
                
DmCloseDatabase(dbRef);
        
MemPtrFree(buf);


What I find is that after creating the database record, the amount of free DB 
Cache remains consistent throughout the rest of my test code.  

Are there any ways to free up memory in the DB Cache while my program is still 
running?

Thanks in advance for your help!

-Ryan




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

Reply via email to