Struct maskerad_memory_allocators::DoubleBufferedAllocator [] [src]

pub struct DoubleBufferedAllocator { /* fields omitted */ }

A double-buffered allocator.

This allocator is a wrapper around two StackAllocators.

It works like a StackAllocator, and allows you to swap the buffers. Their APIs are the same, all the functions of the DoubleBufferedAllocator call the functions of the active StackAllocator.

Refer to the StackAllocator documentation for more information.

Example

use maskerad_memory_allocators::DoubleBufferedAllocator;
//100 bytes for data implementing the Drop trait, 100 bytes for data implementing the `Copy` trait.
let mut allocator = DoubleBufferedAllocator::with_capacity(100, 100);
let mut closed = false;

while !closed {
    //swap the active and inactive buffers of the allocator.
    allocator.swap_buffers();

    //clear the newly active buffer.
    allocator.reset();

    //allocate with the current buffer, leaving the data in the inactive buffer intact.
    //You can use this data during this frame, or the next frame.
    let my_vec: &Vec<u8> = allocator.alloc(|| {
        Vec::with_capacity(10)
    })?;

    assert!(my_vec.is_empty());

    closed = true;
}

Methods

impl DoubleBufferedAllocator
[src]

[src]

Create a DoubleBufferedAllocator with the given capacity (in bytes).

The first capacity is for the memory storage holding data implementing the Drop trait, the second is for the memory storage holding data implementing the Copy trait.

Example

use maskerad_memory_allocators::DoubleBufferedAllocator;
let allocator = DoubleBufferedAllocator::with_capacity(100, 50);

assert_eq!(allocator.capacity(), 100);
assert_eq!(allocator.capacity_copy(), 50);

[src]

Allocates data in the active buffer, returning a mutable reference to the allocated data.

If the allocated data implements Drop, it will be placed in the memory storage storing data implementing the Drop trait. Otherwise, it will be placed in the other memory storage.

Panic

This function will panic if the allocation exceeds the maximum storage capacity of the active allocator.

[src]

Allocates data in the active buffer, returning a mutable reference to the allocated data.

If the allocated data implements Drop, it will be placed in the memory storage storing data implementing the Drop trait. Otherwise, it will be placed in the other memory storage.

Warning

This function doesn't return an error if the allocated data doesn't fit in the StackAllocator's remaining capacity, It doesn't perform any check.

Use if you now that the data will fit into memory and you can't afford the checks.

[src]

Allocates data in the active buffer, returning an immutable reference to the allocated data.

If the allocated data implements Drop, it will be placed in the memory storage storing data implementing the Drop trait. Otherwise, it will be placed in the other memory storage.

Panic

This function will panic if the allocation exceeds the maximum storage capacity of the active allocator.

[src]

Allocates data in the active buffer, returning an immutable reference to the allocated data.

If the allocated data implements Drop, it will be placed in the memory storage storing data implementing the Drop trait. Otherwise, it will be placed in the other memory storage.

Warning

This function doesn't return an error if the allocated data doesn't fit in the active buffer's remaining capacity, It doesn't perform any check.

Use if you now that the data will fit into memory and you can't afford the checks.

[src]

Reset the active buffer's memory storage storing data implementing the Drop trait, dropping all the content residing inside it.

[src]

Reset the active buffer's memory storage storing data implementing the Copy trait.

[src]

Reset partially the active buffer's memory storage storing data implementing the Drop trait, dropping all the content residing between the marker and the first unused memory address of the memory storage.

[src]

Reset partially the active buffer's memory storage storing data implementing the Copy trait.

[src]

Returns the index of the first unused memory address of the active buffer's memory storage storing data implementing the Drop trait.

[src]

Returns the index of the first unused memory address of the active buffer's memory storage storing data implementing the Copy trait.

[src]

Swap the buffers. The inactive one becomes the active.

[src]

Returns the maximum capacity the memory storage storing data implementing the Drop trait can hold.

[src]

Returns the maximum capacity the memory storage storing data implementing the Copy trait can hold.

[src]

Returns a raw pointer to the start of the memory storage used by the memory storage storing data implementing the Drop trait.

[src]

Returns a raw pointer to the start of the memory storage used by the memory storage storing data implementing the Copy trait.

Trait Implementations

impl Debug for DoubleBufferedAllocator
[src]

[src]

Formats the value using the given formatter.