pub fn allocate<T>(
capacity: usize,
) -> Result<(NonNull<T>, usize, Handle), AllocError>
Expand description
Allocate a memory area suitable to hold capacity
consecutive elements of T
.
Returns a pointer, a capacity in T
, and a handle if successful, and an error
otherwise. The capacity can be larger than requested.
The memory must be freed using deallocate
, otherwise the memory leaks. The memory can be freed on a different thread.
§Errors
Allocate errors if the capacity cannot be supported by one of the size classes,
the alignment requirements of T
cannot be fulfilled, if no more memory can be
obtained from the system, or if any syscall fails.
The function also returns an error if lgalloc is disabled.
In the case of an error, no memory is allocated, and we maintain the internal invariants of the allocator.
§Panics
The function can panic on internal errors, specifically when an allocation returned an unexpected size. In this case, the we do no maintain the allocator invariants and the caller should abort the process.
Panics if the thread local variable has been dropped, see std::thread::LocalKey
for details.