Several years ago somebody in here passed along this code to calculate free
RAM but I have just found out that the algorithm is deficient on new devices
(TX and later, at least). Yes, I know there is an article from 2001 in the
KB (bottom of this article) which is very similar so I assume (since it
hasn't been updated since new devices and NVFS came out) it too is lacking.
Here is what I have; what are you using?
// Code from Eric Kenslow and Bozidar Benc (LauncherIII)
// Returns the number of "Kb" free RAM
UInt16 ShowRAM(Boolean show)
{
UInt32 freeRAMBytes, totRAMBytes, freeHeapBytes,
maxHeapBytes, totalBytes, usedBytes, heapBytes = 65536;
static UInt16 lastFreeRAMKBTextLen = 0; // ditto...
UInt16 freeRAMKB;
MemCardInfo(0, NULL, NULL, NULL, NULL, NULL, &totRAMBytes,
&freeRAMBytes);
MemHeapFreeBytes(0, &freeHeapBytes, &maxHeapBytes);
// if (romVersion < 0x02000000) { totalBytes = totRAMBytes; } // not
supported
// else // we only support romVersion > 0x02000000!
totalBytes = (totRAMBytes - heapBytes);
usedBytes = totalBytes - (freeRAMBytes - freeHeapBytes);
freeRAMBytes = totalBytes - usedBytes;
freeRAMKB = (freeRAMBytes / 1024);
return(freeRAMKB);
}
Here is what is in the KB:
static UInt32 GetOSFreeMem( UInt32* totalMemoryP, UInt32* dynamicMemoryP )
{
#define memoryBlockSize (1024L)
UInt32 heapFree;
UInt32 max;
Int16 i;
Int16 nCards;
UInt16 cardNo;
UInt16 heapID;
UInt32 freeMemory = 0;
UInt32 totalMemory = 0;
UInt32 dynamicMemory = 0;
// Iterate through each card to support devices with multiple cards.
nCards = MemNumCards();
for (cardNo = 0; cardNo < nCards; cardNo++)
{
// Iterate through the RAM heaps on a card (excludes ROM).
for (i=0; i < MemNumRAMHeaps(cardNo); i++)
{
// Obtain the ID of the heap.
heapID = MemHeapID(cardNo, i);
// If the heap is dynamic, increment the dynamic memory
total.
if (MemHeapDynamic(heapID))
{
dynamicMemory += MemHeapSize(heapID);
}
// The heap is nondynamic.
else
{
// Calculate the total memory and free memory
of the heap.
totalMemory += MemHeapSize(heapID);
MemHeapFreeBytes(heapID, &heapFree, &max);
freeMemory += heapFree;
}
}
}
// Reduce the stats to KB. Round the results.
freeMemory = freeMemory / memoryBlockSize;
totalMemory = totalMemory / memoryBlockSize;
dynamicMemory = dynamicMemory / memoryBlockSize;
if (totalMemoryP) *totalMemoryP = totalMemory;
if (dynamicMemoryP) *dynamicMemoryP = dynamicMemory;
return (freeMemory);
} // GetOSFreeMem
--
For God, Family and Republic!
My plan to save the world:
More Jesus, Less Government!
http://www.PalmYanoff.com
--
For information on using the PalmSource Developer Forums, or to unsubscribe,
please see http://www.palmos.com/dev/support/forums/