Set v0.1.0

Source
Fills a block of memory with a repeated byte.

Package: Memory

Signature

func Set(
    ptr: *opaque,
    size: uint,
    value: int32
);

Parameters

NameTypeDescription
ptr*opaqueThe first byte of the block to fill.
sizeuintThe number of bytes to write.
valueint32The fill byte, in the low eight bits.

Remarks

Writes size copies of value starting at ptr. Only the low eight bits of value reach memory — the parameter is wider only to match the C fill convention that the Win32 entry point expects, so Set(ptr, size, 0x1FF) fills with 0xFF, not with a truncation error.

A size of 0 writes nothing. Writing past the end of the block is undefined behavior; size must not exceed the size the block was allocated with.

Example

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

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

    Set(buffer, 16, 0xA5);  // every byte is 0xA5
    Set(buffer, 16, 0x1FF); // every byte is 0xFF -- only the low 8 bits land

    Free(buffer);
    return 0;
}

See also

  • Memory — the package overview
  • Zero — the common zero-fill case
  • Copy — fill a block from another block instead of from a byte