_GetHandSize( ) API Library Routine

Returns the usable number of bytes associated with a specified memory block handle hand.

unsigned long _GetHandSize(MHANDLE hand)
MHANDLE hand;            /* Handle of memory block. */

The usable number of bytes is always greater than or equal to the number of bytes most recently requested for this MHANDLE by _AllocHand( ) or by a successful _SetHandSize( ) call.


_GetHandSize() doesn't cause memory reorganization.

For more information on how to create an API library and integrate it with Visual FoxPro, see Accessing the Visual FoxPro API.

The following example allocates memory blocks of various size from 1 to 215 and shows the value returned by _GetHandSize( ) for these allocations. Notice that the value returned by _GetHandSize( ) is only sometimes exactly equal to the size requested by _AllocHand( ); usually it's a bit more.

Visual FoxPro Code


C Code

#include <pro_ext.h>

void putLong(long n)
   Value val;

   val.ev_type = 'I';
   val.ev_long = n;
   val.ev_width = 5;


void FAR Example(ParamBlk FAR *parm)
   MHANDLE mh;
   unsigned int allocSize;

   for (allocSize = 1;; allocSize *= 2)
      if ((mh = _AllocHand(allocSize)) == 0)
         _Error(182);  // "Insufficient memory"
      _PutStr("\n_AllocHand("); putLong(allocSize); _PutStr(")");
      _PutStr("\n_GetHandSize() ="); putLong(_GetHandSize(mh));
      if (allocSize == 32768)

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

Community Additions