On Fri, Apr 26, 2002 at 08:55:48PM -0400, Ted Lowery wrote:
>palm-dev-forum-
>
>Yes, I know *exactly* how much space I will need.
>
>I could do as you suggest, but that is more work that isn't necessary
>since 1) my app is a limited to a specific use, not general use, and
>2) i don't yield to other processes during the data gathering, so
>nothing else can chew up the memory.
>
>So again I'll ask,
>
>What is the proper way to find the storage heap on a particular card?
>ie, differentiate the storage heap from the dynamic heap and the rom
>heaps?
>
>Thanks again for any help.
>
>Cheers, Ted


I'm not entirely sure if it's correct, but this is a function I wrote to
calculate the available space in the storage heap.  It's worked for me well so
far, though if anybody sees a problem, please make it known.  Hope it helps.


/*
 * This function calculates the amount of free space in the storage heap.
 * Because of changes in the Palm OS memory architecture, there is no single
 * function that will work for all versions of the OS.  Pretty lame.
 *
 * The 0x0001 in the if statement is the heap read-only flag mask.
 */
UInt32
MemoryStorageHeapFreeBytes(void)
{
  UInt16        numCards;
  UInt16        numHeaps;
  UInt16        i;
  UInt16        j;
  UInt16        id;
  UInt32        curSize;
  UInt32        maxFree;
  UInt32        totalFree = 0;

  numCards = MemNumCards();
  for (j = 0; j < numCards; j++)
    {
      numHeaps = MemNumRAMHeaps(j);
      for (i = 0; i < numHeaps; i++)
        {
          id = MemHeapID(j, i);
          if (!(MemHeapFlags(id) & 0x0001) && !MemHeapDynamic(id))
            {
              MemHeapFreeBytes(id, &curSize, &maxFree);
              totalFree += curSize;
            }
        }
    }

  return totalFree;
}



-- 
--John Gruenenfelder    Research Assistant, Steward Observatory, U of Arizona
[EMAIL PROTECTED]
"This is the most fun I've had without being drenched in the blood
of my enemies!"
        --Sam of Sam & Max

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

Reply via email to