Revision [17482]
This is an old revision of KeyPgClear made by DkLwikki on 2015-04-01 10:59:40.
CLEAR
Clears or initializes some memory
Syntax:
KeyPgDeclare declare KeyPgSub sub Clear KeyPgCdecl cdecl ( KeyPgByref byref dst KeyPgAs as KeyPgAny any, KeyPgByval byval value KeyPgAs as KeyPgLong long = 0, KeyPgByval byval bytes KeyPgAs as KeyPgUinteger uinteger )
Usage:
Clear( dst, [value], bytes )
Parameters:
dst
starting address of some memory
value
the value to set all bytes equal to
bytes
number of bytes to clear
Description:
Clear sets one or more bytes in memory to a certain value (the default value is zero (0) if not specified). The starting address is taken from a reference to a variable or array element.
NOTE: In order to clear memory referenced by a KeyPgPointer Pointer, it must be dereferenced first. Otherwise, Clear will try to clear the bytes at the pointer variable's memory location.
Examples:
'create an array with 100 elements
Dim array(0 To 99) As Integer
'clear the contents of the array to 0, starting with the first element
Clear array(0), , 100 * SizeOf(Integer)
'allocate 20 bytes of memory
Dim As Byte Ptr p = Allocate(20)
'set each of the first ten bytes to 0
Clear *p, 0, 10
'set each of the next ten bytes to 42
Clear p[10], 42, 10
'check the values of the allocated bytes
For i As Integer = 0 To 19
Print i, p[i]
Next
'deallocate memory
Deallocate p
Dim array(0 To 99) As Integer
'clear the contents of the array to 0, starting with the first element
Clear array(0), , 100 * SizeOf(Integer)
'allocate 20 bytes of memory
Dim As Byte Ptr p = Allocate(20)
'set each of the first ten bytes to 0
Clear *p, 0, 10
'set each of the next ten bytes to 42
Clear p[10], 42, 10
'check the values of the allocated bytes
For i As Integer = 0 To 19
Print i, p[i]
Next
'deallocate memory
Deallocate p
Differences from QB:
- The behavior and usage is new to FreeBASIC
- The keyword CLEAR was used in QB to erase all variables, close all files, and optionally change the stack size. This use is not supported in FreeBASIC.
See also:
Back to Memory Functions