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
Copy Code | |
|---|---|
SET LIBRARY TO MEMAVAIL ? MEMAVAIL() && displays approx. memory available in K | |
C Code
Copy 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
Reference
_AllocHand( ) API Library Routine_FreeHand( ) API Library Routine
_GetHandSize( ) API Library Routine
_HandToPtr( ) API Library Routine
_HLock( ) API Library Routine
_HUnLock( ) API Library Routine
_SetHandSize( ) API Library Routine
Concepts
API Library Routines A-ZOther Resources
Accessing the Visual FoxPro APIAPI Library Routines by Category
Microsoft Visual FoxPro 9 SP2 Help file, VFPX Edition v1.08Send feedback on this topic to the VFPX Help file project team.
2009-2017 Placed under Creative Commons licensing by Microsoft Corporation.