I can get the free memory ok on the T650 but if i
allocate memory in a loop and try to get the free memory left
the value returned never changes. this is the code from palmSource.

eg:

for (i = 0; i < 100; i++)
{
   Allocate some memory....
  call GetOSFreeMem ()....     // always return the same amount
}

/************************************************************************
Sample Code Disclaimer Copyright ) 2001 Palm, Inc. or its subsidiaries.
All rights reserved.

You may incorporate this sample code (the "Code") into your applications
for Palm OS� platform products and may use the Code to develop
such applications without restriction.  The Code is provided to you on
an "AS IS" basis and the responsibility for its operation is 100% yours.
PALM, INC. AND ITS SUBSIDIARIES (COLLECTIVELY, "PALM") DISCLAIM
ALL WARRANTIES, TERMS AND CONDITIONS WITH RESPECT TO THE CODE, EXPRESS,
IMPLIED, STATUTORY OR OTHERWISE, INCLUDING WARRANTIES, TERMS OR
CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
NONINFRINGEMENT AND SATISFACTORY QUALITY.  You are not permitted to
redistribute the Code on a stand-alone basis and you may only
redistribute the Code in object code form as incorporated into your
applications.  TO THE FULL EXTENT ALLOWED BY LAW, PALM ALSO EXCLUDES ANY
LIABILITY, WHETHER BASED IN CONTRACT OR TORT (INCLUDING NEGLIGENCE), FOR
INCIDENTAL, CONSEQUENTIAL, INDIRECT, SPECIAL OR PUNITIVE DAMAGES OF ANY
KIND, OR FOR LOSS OF REVENUE OR PROFITS, LOSS OF BUSINESS, LOSS OF
INFORMATION OR DATA, OR OTHER FINANCIAL LOSS ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THE CODE.  The Code is subject
to Restricted Rights for U.S. government users and export regulations.

SAMPLE NAME: GetOSFreeMem function

FILE:        GetOSFreeMem.c

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!

REVISION HISTORY:   Name    Date         Description
                    ----    ----         -----------
                    mt      09/19/00     initial version
                    mak     01/11/01    comments/dynamic memory conversion
***********************************************************************/

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 information on using the PalmSource Developer Forums, or to unsubscribe, 
please see http://www.palmos.com/dev/support/forums/

Reply via email to