Struct maskerad_memory_allocators::DoubleBufferedAllocatorCopy [] [src]

pub struct DoubleBufferedAllocatorCopy { /* fields omitted */ }

A double-buffered allocator for data implementing the Copy trait.

This allocator is a wrapper around two StackAllocatorCopy. It works like a StackAllocatorCopy, and allows you to swap the buffers.

Example

use maskerad_memory_allocators::DoubleBufferedAllocatorCopy;


let mut allocator = DoubleBufferedAllocatorCopy::with_capacity(100); //100 bytes.
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_i32 = allocator.alloc(|| {
        47 as i32
    });

    closed = true;
}

Methods

impl DoubleBufferedAllocatorCopy
[src]

[src]

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

Example

#![feature(alloc)]
use maskerad_memory_allocators::DoubleBufferedAllocatorCopy;

let allocator = DoubleBufferedAllocatorCopy::with_capacity(100);

assert_eq!(allocator.active_buffer().storage().borrow().capacity(), 100);
assert_eq!(allocator.inactive_buffer().storage().borrow().capacity(), 100);

[src]

Allocates data in the active buffer.

Panic

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

[src]

Resets completely the active buffer, setting the index of the first unused memory address to 0, the bottom of the memory chunk.

[src]

Resets partially the active buffer, setting the index of the first unused memory address to the marker.

[src]

Returns the index of the first unused memory address in the active buffer.

[src]

Return an immutable reference to the active StackAllocatorCopy.

Most of the time, you should not have to access the stack allocators directly. This structure mimics the StackAllocatorCopy's API and have the swap_buffers() function to swap the active allocator to the inactive one, and vice-versa.

[src]

Return an immutable reference to the inactive StackAllocatorCopy.

Most of the time, you should not have to access the stack allocators directly. This structure mimics the StackAllocatorCopy's API and have the swap_buffers() function to swap the active allocator to the inactive one, and vice-versa.

[src]

Swap the buffers. The inactive one becomes the active.