次の方法で共有


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

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

SET LIBRARY TO GETHANDS

C 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

Reference

_AllocHand( ) API Library Routine

_FreeHand( ) API Library Routine

_HandToPtr( ) API Library Routine

_HLock( ) API Library Routine

_HUnLock( ) API Library Routine

_MemAvail( ) API Library Routine

_SetHandSize( ) API Library Routine

Other Resources

API Library Construction