Class Allocator

Memory allocator for a device

class Allocator
  : AtomicRefCounted ;

Properties

NameTypeDescription
device[get] DeviceDevice this allocator is bound to.
refCount[get] ulongAtomically loads the number of active references.
refCountShared[get] ulongAtomically loads the number of active references.

Methods

NameDescription
allocate (requirements, options) Allocate memory for the given requirements
allocateBuffer (usage, size, options) Create a buffer, then allocate and bind memory for its requirements
allocateImage (info, options) Create an image, then allocate and bind memory for its requirements
collectStats ()
dispose () Dispose the underlying resource
rcLock () Returns whether the refCount >= 1. This increases the refCount by 1. rcLock should be used to keep weak reference and ensures that the resource is not disposed. The operation is atomic.
rcLockShared () Returns whether the refCount >= 1. This increases the refCount by 1. rcLock should be used to keep weak reference and ensures that the resource is not disposed. The operation is atomic.
release (disposeOnZero) Atomically decrement the reference count. If refCount reaches zero, and disposeOnZero is set, the object is locked with its own mutex, and dispose is called. In most cases, the calling code should set disposeOnZero, unless it is intended to release the object to give it away. (such as at the end of a builder function)
releaseShared (disposeOnZero) Atomically decrement the reference count. If refCount reaches zero, and disposeOnZero is set, the object is locked with its own mutex, and dispose is called. In most cases, the calling code should set disposeOnZero, unless it is intended to release the object to give it away. (such as at the end of a builder function)
retain () Atomically increment the reference count.
retainShared () Atomically increment the reference count.
tryAllocate (requirements, memoryTypeIndex, options, layout, result) Attempt to allocate memory for the given index and for given requirements. If successful, result is filled with necessary data.