Click or drag to resize

MemGrpAlloc Function

X#
Allocate a new memory buffer in a group.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.21
Syntax
 FUNCTION MemGrpAlloc(
	wGroup AS DWORD,
	wBytes AS DWORD
) AS IntPtr
Request Example View Source

Parameters

wGroup
Type: DWord
The group to which the newly allocated memory buffer will belong.
This group should have already been opened by MemGrpOpen().
wBytes
Type: DWord
The number of bytes to allocate.

Return Value

Type: IntPtr
A pointer to the newly allocated space if there is sufficient memory available; otherwise, a NULL_PTR is returned. You should always check the return value for a successful allocation.
Remarks
MemGrpAlloc() allocates a memory buffer of at least wBytes. Since memory is allocated in increments of 32 bytes, some extra space may be allocated.
For example, a request for even 1 byte will allocate 32 bytes. Space allocated by MemGrpAlloc() is freed by MemGrpClose().
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 MemGrpAlloc():
X#
 1Function Start()
 2    LOCAL ptrCurrent AS PTR
 3    LOCAL wGroup AS DWORD
 4    LOCAL lRet AS LOGIC
 5    wGroup := MemGrpOpen()        // Need to have a
 6                                // group ready first
 7    IF wGroup != 0
 8        ptrCurrent := MemGrpAlloc(wGroup, 100)
 9        MemGrpClose(wGroup)
10        lRet := FALSE
11    ELSE
12        lRet := TRUE
13    ENDIF
14    RETURN lRet
See Also