std/ffi/libc/mem
libc memory primitives. All bindings use @link(symbol = …) to resolve
directly against libc — no Rust wrapper. Callers wrap usage inunsafe { } blocks.
Reference: https://en.cppreference.com/w/c/memory
Free functions
| Type | Method and description |
|---|---|
| libc_malloc(n : i64) : ptr Allocate n uninitialised bytes. Returns the block, or NULL on failure.Free with libc_free. @param n size in bytes. |
| libc_calloc(count : i64, size : i64) : ptr Allocate count * size bytes, zero-initialised. Returns the block, orNULL on failure. @param size size of one element, in bytes. |
| libc_realloc(p : ptr, n : i64) : ptr Resize the block p to n bytes, preserving existing contents. Returnsthe (possibly moved) block, or NULL on failure (leaving p valid). |
| libc_free(p : ptr) : void Release a block previously returned by libc_malloc / libc_calloc /libc_realloc. A NULL p is a no-op. |
| libc_memcpy(dst : ptr, src : ptr, n : i64) : ptr Copy n bytes from src to dst; the regions must not overlap. |
| libc_memmove(dst : ptr, src : ptr, n : i64) : ptr Copy n bytes from src to dst, overlap-safe. |
| libc_memset(dst : ptr, c : i32, n : i64) : ptr Fill n bytes of dst with the low byte of c. |
| libc_memcmp(a : ptr, b : ptr, n : i64) : i32 Compare n bytes of a and b lexicographically. |
| libc_strlen(s : ptr) : i64 Length in bytes of the NUL-terminated C string at s (excluding the NUL). |
| libc_strcmp(a : ptr, b : ptr) : i32 Compare two NUL-terminated C strings lexicographically. |
| libc_strncmp(a : ptr, b : ptr, n : i64) : i32 Compare at most n bytes of two NUL-terminated C strings lexicographically. |
Method detail
#libc_malloc
Allocate n uninitialised bytes. Returns the block, or NULL on failure.
Free with libc_free. @param n size in bytes.
#libc_calloc
Allocate count * size bytes, zero-initialised. Returns the block, orNULL on failure. @param size size of one element, in bytes.
count number of elements to allocate.#libc_realloc
Resize the block p to n bytes, preserving existing contents. Returns
the (possibly moved) block, or NULL on failure (leaving p valid).
p block to resize, from a prior libc allocation (caller-managed).n new size in bytes.#libc_free
Release a block previously returned by libc_malloc / libc_calloc /libc_realloc. A NULL p is a no-op.
p block to release; ownership returns to the allocator.#libc_memcpy
Copy n bytes from src to dst; the regions must not overlap.
dst destination buffer (caller-managed).src source buffer (caller-managed).n byte count. @return dst.#libc_memmove
Copy n bytes from src to dst, overlap-safe.
dst destination buffer (caller-managed).src source buffer (caller-managed).n byte count. @return dst.#libc_memset
Fill n bytes of dst with the low byte of c.
dst destination buffer (caller-managed).c fill value; only its low byte is used.n byte count. @return dst.#libc_memcmp
Compare n bytes of a and b lexicographically.
a first buffer (caller-managed).b second buffer (caller-managed).n byte count. @return <0, 0, or >0.#libc_strlen
Length in bytes of the NUL-terminated C string at s (excluding the NUL).
s pointer to a NUL-terminated C string (caller-managed).#libc_strcmp
Compare two NUL-terminated C strings lexicographically.
a first NUL-terminated C string (caller-managed).b second NUL-terminated C string (caller-managed).<0, 0, or >0.#libc_strncmp
Compare at most n bytes of two NUL-terminated C strings lexicographically.
a first NUL-terminated C string (caller-managed).b second NUL-terminated C string (caller-managed).n maximum bytes to compare. @return <0, 0, or >0.