Skip to content
class

MetalBuffer

MetalBuffer

Plain descriptor for a Metal buffer that backs Lucid's SharedStorage.

Holds the raw CPU pointer + opaque MTL handle + size for a Metal shared-memory buffer. This struct does not own anything — lifetime is managed externally (see OwnedMetalBuffer for the RAII form). On Apple Silicon, cpu_ptr and mtl_handle reference the same physical pages, so CPU writes are immediately visible to GPU kernels (and vice versa) without an explicit transfer.

See Also

OwnedMetalBuffer — RAII wrapper around this descriptor.

Attributes

cpu_ptrvoid*
CPU-accessible virtual address of the buffer. nullptr if the buffer is uninitialised or has been deallocated.
mtl_handlevoid*
Opaque CFRetain'd id<MTLBuffer> cast to void* to keep this header free of Objective-C types. nullptr when invalid.
nbytesstd::size_t
Allocation size in bytes. Always 0 on an uninitialised value.

Notes

Use make_metal_shared for everyday allocation — manual pairing of allocate_shared and deallocate_shared is only needed for low-level pool code.