Zero v0.1.0

Source
Fills a block of memory with zero bytes.

Package: Memory

Signature

func Zero(ptr: *opaque, size: uint);

Parameters

NameTypeDescription
ptr*opaqueThe first byte of the block to clear.
sizeuintThe number of bytes to clear.

Remarks

Writes size zero bytes starting at ptr — the same thing as Set(ptr, size, 0), which is exactly how it is implemented everywhere except Windows, where it lowers to RtlZeroMemory.

This is the usual companion to Alloc, whose blocks come back uninitialized. A size of 0 writes nothing, and writing past the end of the block is undefined behavior.

Example

import Memory::{ Alloc, Free, Zero };

func Main() -> int {
    let buffer = Alloc(1024);

    Zero(buffer, 1024); // now safe to read before writing

    Free(buffer);
    return 0;
}

See also

  • Memory — the package overview
  • Set — fill with a byte other than zero
  • Alloc — the source of the uninitialized block