Skip to content
fn

allocate_shared

→MetalBuffer
MetalBuffer allocate_shared(int nbytes)

Allocate a new MTLResourceStorageModeShared buffer of size nbytes.

The returned buffer is backed by unified-memory pages: the CPU pointer and the Metal buffer handle reference the same physical bytes, with no transfer required between domains.

See Also

make_metal_shared — ref-counted variant.

Parameters

nbytesstd::size_t
Allocation size in bytes. Zero-sized allocations are legal and return a buffer with cpu_ptr == nullptr.

Returns

MetalBuffer

A populated descriptor on success; a zero-initialised value on allocation failure (e.g. out-of-memory). Callers should check mtl_handle != nullptr before use.

Notes

The returned buffer must be released with deallocate_shared to avoid leaking the underlying Metal allocation.