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

' 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 

Related Function

FillMemory

Category

Memory

Back to the index.


Last Modified: July 26, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information

Go to Paul Kuliniewicz's Home Page.
E-mail: rogue953@hotmail.com
This page is at http://skyscraper.fortunecity.com/transmission/45/api/z/zeromemory.html