pub struct InternalAllocator;
Expand description
This is the allocator for Internal Working RAM.
Internal Working RAM (IWRAM) is the fastest RAM on the Game Boy Advance but is also the
very limited in quantity (32kb). The default allocator for agb
is the ExternalAllocator
which allocates into External Working RAM (EWRAM). EWRAM is more plentiful (256kb), so you
should prefer to allocate into that and only allocate into IWRAM if you have specific cases
you need to be faster.
This implements the allocator trait, so is meant to be used in specifying where certain structures should be allocated.
#![feature(allocator_api)]
extern crate alloc;
use agb::InternalAllocator;
use alloc::vec::Vec;
let mut v = Vec::new_in(InternalAllocator);
v.push("hello, world");
assert!(
(0x0300_0000..0x0300_8000).contains(&(v.as_ptr() as usize)),
"the address of the vector is inside iwram"
);
Trait Implementations§
Source§impl Allocator for InternalAllocator
impl Allocator for InternalAllocator
Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api
)Attempts to allocate a block of memory. Read more
Source§unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout)
🔬This is a nightly-only experimental API. (
allocator_api
)Deallocates the memory referenced by
ptr
. Read more§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api
)Behaves like
allocate
, but also ensures that the returned memory is zero-initialized. Read more§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api
)Attempts to extend the memory block. Read more
§unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api
)Behaves like
grow
, but also ensures that the new contents are set to zero before being
returned. Read moreSource§impl Clone for InternalAllocator
impl Clone for InternalAllocator
Source§fn clone(&self) -> InternalAllocator
fn clone(&self) -> InternalAllocator
Returns a duplicate of the value. Read more
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for InternalAllocator
impl RefUnwindSafe for InternalAllocator
impl Send for InternalAllocator
impl Sync for InternalAllocator
impl Unpin for InternalAllocator
impl UnwindSafe for InternalAllocator
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)