JavaScript Editor js editor     Web development 



Main Page

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. */

Remarks

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.

Note:
_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.

Example

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

В Copy Code
SET LIBRARY TO GETHANDS

C Code

В Copy Code
#include <pro_ext.h>

void putLong(long n)
{
   Value val;

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

   _PutValue(&val);
}

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));
      _FreeHand(mh);
      if (allocSize == 32768)
      {
         break;
      }
   }
}

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

See Also



JavaScript Editor js editor     Web development 
R7