Repository navigation
Clear
Home › Memory Functions › Clear
Sets a number of bytes, starting at a variable, to zero or to a given value.
Declare Sub Clear cdecl ( ByRef dst As Any, ByVal value As Long = 0, ByVal bytes As UInteger )dstvaluebytes
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 Pointer, it must be dereferenced first (or else specifying in argument term the ByVal keyword in front of the pointer name). Otherwise, Clear will try to clear the bytes at the pointer variable's memory location.
Clear( dst, [value], bytes )
- The behavior and usage is new to FreeBASIC
The keyword
CLEARwas used in QB to erase all variables, close all files, and optionally change the stack size. This use is not supported in FreeBASIC.
'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 pCategory: Memory Functions
Kind: sub
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing