PDA

View Full Version : Memory problem


jmding
04-08-2002, 07:52 PM
Why malloc fails sometimes. The code is as following:

if(ISHELL_CreateInstance(aeeApp.m_pIShell, AEECLSID_HEAP, (void **)&pIHeap) == SUCCESS) //ok
{
iMem=IHEAP_GetMemStats(pIHeap); //ok
iFree=200000-iMem; //ok
iFree=iFree/2;
if(IHEAP_CheckAvail(pIHeap,iFree)) //fail sometimes
{
pTest=MALLOC(iFree);
if(pTest) FREE(pTest);
}
IHEAP_Release(pIHeap);
}

Mahesh
04-08-2002, 09:48 PM
1. You should use ISHELL_Get DeviceInfo to determine the amount of RAM available on the device (this will make your application more portable).

2. The available memory maybe fragmented. Although you may have 75K available, the largest contiguous block may only be 30K.

--Mahesh
BREW Support

jmding
04-09-2002, 12:05 AM
Thanks very much! But my program displays thumbnails and often malloc and free memory. So i have another problem now. I want to know how brew manages memory and how to malloc 50k memory successfully?

Mahesh
04-11-2002, 03:03 PM
The following knowledgebase article provides some tips on how to effectively use the heap on the device:

http://www.qualcomm.com/brew/developer/support/kb/42.html

Generally, if you free memory in the reverse order of allocation, you can reduce fragmentation.

--Mahesh
BREW Support