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.5
Syntax
 FUNCTION MemSet(
	ptrBuffer AS IntPtr,
	bValue AS BYTE,
	wCount AS DWORD
) AS IntPtr

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#
1FUNCTION MemReplicate() AS VOID
2    LOCAL ptrC AS PTR
3    ptrC := MemAlloc(10)
4    ptrC := MemSet(ptrC, Asc("A"),10)
5    ? ptrC                    // AAAAAAAAAA
6    MemFree(ptrC)
This example uses MemSet() to change all characters of a PSZ to "Z":
X#
1FUNCTION PszQ()
2    LOCAL pszS := "ABC" AS PSZ
3    // Asc("Z") = 90
4    MemSet(pszS, 90,3)
5    ? pszS                    // ZZZ
See Also