Skip to content

CLEAR


清除或初始化一段内存

语法

declare sub Clear cdecl ( byref dst as any, byval value as long = 0, byval bytes as uinteger )

用法

Clear( dst, [value], bytes )

参数

dst

内存的起始地址。

value

要将所有字节设置为的值。

bytes

要清除的字节数。

说明

Clear 将内存中的一个或多个字节设置为指定值(若未指定,默认值为零 0)。起始地址取自对变量或数组元素的引用。

注意:要清除由 Pointer 引用的内存,必须先对其解引用(或在参数中在指针名前加 Byval 关键字),否则 Clear 将尝试清除指针变量本身所在内存位置的字节。

示例

vb
'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

与 QB 的差异

  • FreeBASIC 中的行为和用法为新增内容
  • QB 中的 CLEAR 关键字用于清除所有变量、关闭所有文件,以及可选地更改栈大小。此用法在 FreeBASIC 中不受支持。

另请参阅

  • Erase
  • Reset

返回 目录

基于 FreeBASIC 官方文档翻译 如有侵权请联系我们删除
FreeBASIC 是开源项目,与微软公司无隶属关系