_FreeHand( ) API Library Routine Example

The following example allocates 1024 blocks of 16384-byte memory blocks, for a total of 16 MB, freeing each memory block using _FreeHand( ) before allocating the next.

Visual FoxPro Code

SET LIBRARY TO FREEHAND

C Code

#include <pro_ext.h>

void FAR Example(ParamBlk FAR *parm)
{
   MHANDLE mh;
   int i;

   for (i = 0; i < 1024; i++)
   {
      if ((mh = _AllocHand(16384)) == 0)
      {
         _Error(182);  // "Insufficient memory"
      }
      _FreeHand(mh);
   }
}

FoxInfo myFoxInfo[] = {
   {"ONLOAD", (FPFI) Example, CALLONLOAD, ""},
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};