Click or drag to resize

MemFree Function

X#
Deallocate a specified memory buffer.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION MemFree(
	ptrBuffer AS IntPtr
) AS WORD
Request Example View Source

Parameters

ptrBuffer
Type: IntPtr
A pointer to a previously allocated memory buffer.
If an invalid pointer is specified, a message box informs you of the failed attempt.

Return Value

Type: Word
0 if successful; otherwise, 65,535.
Remarks
MemFree() is a memory function used to free up memory allocated by MemAlloc().
The number of bytes freed is the number of bytes that were previously allocated by MemAlloc().
Tip Tip
This function allows the direct manipulation of a memory location and should be used with extreme care.
Remarks
Tip Tip
The Static Memory Functions (MemAlloc, MemSet etc) are included for compatibility only. In most cases the static memory blocks can (and should) be replaced with arrays of bytes.
Many of the functions in the runtime that take memory blocks as parameter, such as the low level IO functions, now have overloads that take arrays of bytes as parameter.
We recommend that you use these overloads, because their performance is somewhat better.
Examples
This example uses MemFree() to deallocate a newly allocated block:
X#
1LOCAL ptrBuff AS PTR
2ptrBuff := MemAlloc(128)
3IF ptrBuff = NULL_PTR
4    ? "Allocation failed"
5ELSE
6    MemFree(ptrBuff)
7ENDIF
See Also