Skip to content
CryoCryo home
Stdlibcore

mem

import std::core::mem; · source

Memory utilities

function copy<T>(dest: T*, src: T*, count: u64) -> void;
function copy_overlapping<T>(dest: T*, src: T*, count: u64) -> void;
function zero<T>(dest: T*, count: u64) -> void;
function swap<T>(a: T*, b: T*) -> void;
function offset<T>(ptr: T*, count: i64) -> T*;
function align_up(ptr: void*, alignment: u64) -> void*;
function align_down(ptr: void*, alignment: u64) -> void*;
function is_aligned(ptr: void*, alignment: u64) -> boolean;
function transmute<From, To>(value: From) -> To;
function drop<T>(_v: T) -> void;

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.