Skip to content
CryoCryo home
Stdlibcore

mem

import std::core::mem; · source

Free Functions

Memory utilities

core::mem is typed wrappers over the memory intrinsics. Everything operates on pointers you already hold; nothing here allocates.

FunctionEffect
copyCopy count values. Regions must not overlap.
copy_overlappingSame, handling overlap correctly.
zeroZero count values.
swapSwap the two values.
offsetStep by elements, not bytes. Negative walks backwards.
align_up / align_downRound to a power-of-two boundary.
is_alignedboolean
transmuteReinterpret the bytes. Aborts if the sizes differ; bit-pattern validity is your problem.
dropTake ownership of a value and end its scope now. The compiler's synthesised drop runs on the way out; for a type with no destructor it is a no-op.

function copy<T>(dest: T*, src: T*, count: u64) -> void;

Copy count values of type T from src to dest. Regions must not overlap.

function copy_overlapping<T>(dest: T*, src: T*, count: u64) -> void;

Copy count values from src to dest, correctly handling overlap.

function zero<T>(dest: T*, count: u64) -> void;

Zero count values of type T starting at dest.

function swap<T>(a: T*, b: T*) -> void;

Swap the values at a and b.

function offset<T>(ptr: T*, count: i64) -> T*;

Offset a typed pointer by count elements (not bytes). Negative values walk backwards.

function align_up(ptr: void*, alignment: u64) -> void*;

Round ptr up to the next multiple of alignment. alignment must be a power of two.

function align_down(ptr: void*, alignment: u64) -> void*;

Round ptr down to the previous multiple of alignment.

function is_aligned(ptr: void*, alignment: u64) -> boolean;

function transmute<From, To>(value: From) -> To;

Reinterpret the bytes of value as a To. Aborts if the two types have different sizes. Bit-pattern validity is the caller's problem.

function drop<T>(_v: T) -> void;

Explicitly drop a value of type T. This is a no-op for types that do not implement a destructor. The caller is responsible for ensuring that any resources held by _v are properly released if necessary.