ZeroMemory Function

Declare Sub ZeroMemory Lib "kernel32.dll" Alias "RtlZeroMemory" (Destination As Any, ByVal Length As Long)

Platforms

Description & Usage

ZeroMemory fills a location in memory with zeros. The function sets each byte starting at the given memory location to zero. The memory location is identified by a pointer to the memory address.

Return Value

ZeroMemory does not return a value.

Visual Basic-Specific Issues

A pointer to any variable can be automatically generated merely by passing that variable as Destination. However, if either a String or a Long holding the desired memory address is passed, the ByVal keyword must preceed it.

Parameters

Destination
A pointer to the location in memory (often the memory address of a variable) to begin filling with zeros.
Length
The number of memory bytes, beginning with the address identified by Destination, to set to zeros.

Example

' This code is licensed according to the terms and conditions listed here.

' Initialize all the elements in an array to the value 0.
Dim bytearray(0 To 9) as Byte  ' array of 10 bytes
Dim c As Integer  ' counter variable

' Fill the memory at bytearray() with zeros.  Note that, to identify the pointer
' to bytearray()'s memory location, it is passed as normal.
ZeroMemory bytearray(0), 10  ' zero out 10 bytes
' Display the results to verify that it worked.
For c = 0 To 9  ' loop through each element
  Debug.Print bytearray(c);  ' each value displayed will be 0
Next c 

See Also

FillMemory

Category

Memory

Go back to the alphabetical Function listing.
Go back to the Reference section index.


Last Modified: July 26, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/z/zeromemory.html