Hi Yen !

I found the following function at http://oasis.palm.com/dev/kb/ - the PalmOS
developer knowledge base:

HTH
_____
PE|RA

 /***********************************************************************
 *
 * FUNCTION:     GetOSFreeMem
 *
 * DESCRIPTION:  Determine the amount of free memory and the amount of
 *               total memory in the current device.  Results are expressed
 *               in KB. The returned value is the amount of free memory in
all
 *               heaps other than the dynamic heap.  This is very ACCURATE!
 *
 * RETURNED:     nothing
 *
 ***********************************************************************/

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);
}




"James Nicholls" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:52202@palm-dev-forum...
>
> MemHeapFreeBytes will tell you how much is free. Heap 0 is the normal heap
> used to allocate dynamic memory.
>
> Cheers,
> James.
>
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of
> [EMAIL PROTECTED]
> Sent: Friday, 8 June 2001 11:40
> To: Palm Developer Forum
> Subject: How to read out the palm free memory size
>
>
> Hi All,
>
> I need to know about the size of free memory left at Palm by software. Is
> there anybody about it? Thanks
>
> Best Regards,
> Yen
>
>
>
> --
> For information on using the Palm Developer Forums, or to unsubscribe,
> please see http://www.palmos.com/dev/tech/support/forums/
>
>
>



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

Reply via email to