Trait object_alloc::UntypedObjectAlloc [] [src]

pub unsafe trait UntypedObjectAlloc {
    fn layout(&self) -> Layout;
unsafe fn alloc(&mut self) -> Result<*mut u8, Exhausted>;
unsafe fn dealloc(&mut self, x: *mut u8); fn oom(&mut self) -> ! { ... } }

An allocator for objects whose type or size is not known at compile time.

UntypedObjectAlloc is like ObjectAlloc, except that the size that it allocates may be configured at runtime. Also unlike ObjectAlloc, UntypedObjectAllocs make no guarantees about initialization of objects. An individual implementation of UntypedObjectAlloc may decide to make such guarantees, but it is not required in order to be a correct implementation of this trait, and the correctness of unsafe code must not rely on this behavior.

Required Methods

Obtains the Layout of allocated objects.

layout returns a Layout object describing objects allocated by this UntypedObjectAlloc. All objects obtained via alloc are guaranteed to satisfy this Layout.

Allocates an object of type T.

The memory returned by alloc is guaranteed to abide by the Layout returned from layout.

Deallocates an object previously returned by alloc.

If x was not obtained through a call to alloc, or if x has already been dealloc'd, the behavior of dealloc is undefined.

Provided Methods

Allocator-specific method for signalling an out-of-memory condition.

oom aborts the thread or process, optionally performing cleanup or logging diagnostic information before panicking or aborting.

oom is meant to be used by clients which are unable to cope with an unsatisfied allocation request, and wish to abandon computation rather than attempt to recover locally. The allocator likely has more insight into why the request failed, and thus can likely print more informative diagnostic information than the client could.

Implementations of the oom method are discouraged from infinitely regressing in nested calls to oom. In practice this means implementors should eschew allocating, especially from self (directly or indirectly).

Implementions of alloc are discouraged from panicking (or aborting) in the event of memory exhaustion; instead they should return an error and let the client decide whether to invoke this oom method in response.

Implementors