Click or drag to resize

MemSet Function

Fill a memory buffer with a specified character.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.10
Syntax
 FUNCTION MemSet(
	ptrBuffer AS IntPtr,
	bValue AS BYTE,
	wCount AS DWORD
) AS IntPtr
View Source

Parameters

ptrBuffer
Type: IntPtr
A pointer to the memory buffer to fill.
bValue
Type: Byte
The code for the character, as a number from 0 to 255.
wCount
Type: UInt32
The number of bytes to fill.

Return Value

Type: IntPtr
A pointer to the filled memory buffer.
Remarks
MemSet() sets the first <wCount> characters of the memory buffer pointed to by <ptrBuffer> to a specified character.
Tip Tip
This function allows the direct manipulation of a memory location and should be used with extreme care.
Examples
This example uses MemSet() to fill up all characters of an allocated buffer with "A":
X#
FUNCTION MemReplicate() AS VOID
        LOCAL ptrC AS PTR
        ptrC := MemAlloc(10)
        ptrC := MemSet(ptrC, Asc("A"),10)
        ? ptrC                                        // AAAAAAAAAA
        MemFree(ptrC)
This example uses MemSet() to change all characters of a PSZ to "Z":
X#
FUNCTION PszQ()
        LOCAL pszS := "ABC" AS PSZ
        // Asc("Z") = 90
        MemSet(pszS, 90,3)
        ? pszS                                        // ZZZ
See Also