MkAllocatorRes

Struct MkAllocatorRes 

Source
pub struct MkAllocatorRes { /* private fields */ }
Expand description

Bevy resource wrapping the memkit allocator.

Use this to access frame allocations in your systems:

fn my_system(alloc: Res<MkAllocatorRes>) {
    let data = alloc.frame_alloc::<MyStruct>();
    // data is valid until end of frame
}

Implementations§

Source§

impl MkAllocatorRes

Source

pub fn new(config: MkConfig) -> Self

Create a new allocator resource with the given config.

Source

pub fn allocator(&self) -> &MkAllocator

Get a reference to the underlying allocator.

Source

pub fn is_frame_active(&self) -> bool

Check if a frame is currently active.

Source

pub fn frame_alloc<T>(&self) -> *mut T

Allocate a value in the current frame’s arena.

Returns a raw pointer to uninitialized memory. You must initialize it.

§Panics

Panics if called outside of an active frame.

Source

pub fn frame_slice<T>(&self, len: usize) -> Option<MkFrameSlice<'_, T>>

Allocate a slice in the current frame’s arena.

Returns an MkFrameSlice wrapper if successful.

Source

pub fn frame_box<T>(&self, value: T) -> Option<MkFrameBox<'_, T>>

Allocate and initialize a value in the frame arena.

Returns an MkFrameBox wrapper if successful.

Methods from Deref<Target = MkAllocator>§

Source

pub fn config(&self) -> &MkConfig

Get the configuration.

Source

pub fn begin_frame(&self)

Begin a new frame. Must be paired with end_frame().

Source

pub fn end_frame(&self)

End the current frame. Resets frame arena.

Source

pub fn frame(&self) -> u64

Get the current frame number.

Source

pub fn frame_alloc<T>(&self) -> *mut T

Allocate from the frame arena.

Source

pub fn frame_box<T>(&self, value: T) -> Option<MkFrameBox<'_, T>>

Allocate a value in the frame arena and return a box.

Source

pub fn frame_slice<T>(&self, len: usize) -> Option<MkFrameSlice<'_, T>>

Allocate a slice in the frame arena.

Source

pub fn frame_vec<T>(&self, capacity: usize) -> Option<MkFrameVec<'_, T>>

Allocate a vector in the frame arena with the given capacity.

Source

pub fn pool_box<T>(&self, value: T) -> Option<MkPoolBox<T>>

Allocate from the pool.

Source

pub fn heap_box<T>(&self, value: T) -> Option<MkHeapBox<T>>

Allocate from the heap.

Source

pub fn scope(&self) -> MkScope<'_>

Create a scoped frame guard.

Source

pub fn frame_head(&self) -> usize

Get the current frame head position (for checkpointing).

Source

pub fn reset_frame_to(&self, pos: usize)

Reset frame to a checkpoint position.

Source

pub fn stats(&self) -> GlobalStats

Get global statistics.

Trait Implementations§

Source§

impl Deref for MkAllocatorRes

Source§

type Target = MkAllocator

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl Resource for MkAllocatorRes
where Self: Send + Sync + 'static,

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

impl<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ConditionalSend for T
where T: Send,