_MemAvail( ) API Library Routine
Determines whether enough memory is available for you to allocate a memory handle of size bytes.
BOOL _MemAvail(unsigned long size)
unsigned int size; /* Size of memory handle in bytes. */
Remarks
The function returns True (an integer other than 0) if enough memory is available, or False (0) if not.
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 builds a linked list of 1K memory handle allocations until available memory is used. It then frees allocations and returns the number of allocations made. _MemAvail( ) is used to terminate the first while loop.
Visual FoxPro Code
SET LIBRARY TO MEMAVAIL
? MEMAVAIL() && displays approx. memory available in K
C Code
#include <pro_ext.h>
#define ALLOCSIZE 1024
FAR Example(ParamBlk FAR *parm)
{
int nHandles = 0;
MHANDLE head = 0, mh;
while (_MemAvail(ALLOCSIZE))
{
mh = _AllocHand(ALLOCSIZE);
*((MHANDLE *) _HandToPtr(mh)) = head;
head = mh;
nHandles++;
}
_RetInt(nHandles, 10);
while (head != 0)
{
mh = *((MHANDLE *) _HandToPtr(head));
_FreeHand(head);
head = mh;
}
}
FoxInfo myFoxInfo[] = {
{"MEMAVAIL", (FPFI) Example, 0, ""},
};
FoxTable _FoxTable = {
(FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};
See Also
Concepts
Reference
_AllocHand( ) API Library Routine
_FreeHand( ) API Library Routine
_GetHandSize( ) API Library Routine
_HandToPtr( ) API Library Routine
_HUnLock( ) API Library Routine
_SetHandSize( ) API Library Routine