Memory allocation
This module contains memory allocators and the Allocator trait implemented by them.
| Kind | Name | Description |
|---|---|---|
| Trait | Allocator | Allocators. |
| Struct | Bda | The brain-dead allocator |
| Typedef | FbHeap | |
| Typedef | Heap | |
| Struct | Libc | The libc allocator |
| Struct | NoMem | Heap without memory backing it |
| Struct | TaAlloc | Throw-away allocator. |
| Struct | TaPool | The memory pool of TaAllo. |
| Name | Description |
|---|---|
| empty_ptr | Returns a non-null pointer that points to a valid address and has pointer alignment. |
| Name | Description |
|---|---|
| MAX_SIZE | The maximum size of an allocation |
The maximum size of an allocation is limited to the maximum value that can be represented in an isize. This limit is checked by the allocators and allocation will fail if a too-large allocation is requested. The limit is also available through the MAX_SIZE constant.
Heap and FbHeapThis module contains two type definitions that affect the default behavior of lrs. The Heap allocator is the default allocator used by types that have an allocator argument. For example, Vec<T> is the same as Vec<T, Heap>. The FbHeap allocator is the allocator used by functions that don't allocate in the common case and fall back to allocating if they have to. For example, File::open will try to construct a null-terminated path argument on the stack but falls back to allocating with the FbHeap allocator if the path is too long.
The Jemalloc allocator is only available if lrs was compiled with the jemalloc option.
The following example performs a simple allocate-store-read-free operation.
unsafe {
let mem: *mut u8 = try!(Bda::allocate());
*mem = 1;
println!("{}", *mem);
Bda::free(mem);
}