pub struct GlobalAllocator { /* private fields */ }Expand description
The global allocator used by ArceOS when TLSF is enabled.
Implementations§
Source§impl GlobalAllocator
impl GlobalAllocator
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Creates an empty GlobalAllocator.
Sourcepub fn init(&self, start_vaddr: usize, size: usize) -> AllocResult
pub fn init(&self, start_vaddr: usize, size: usize) -> AllocResult
Initializes the allocator with the given region.
Sourcepub fn add_memory(&self, start_vaddr: usize, size: usize) -> AllocResult
pub fn add_memory(&self, start_vaddr: usize, size: usize) -> AllocResult
Add the given region to the allocator.
Sourcepub fn alloc(&self, layout: Layout) -> AllocResult<NonNull<u8>>
pub fn alloc(&self, layout: Layout) -> AllocResult<NonNull<u8>>
Allocate arbitrary number of bytes.
Sourcepub fn alloc_pages(
&self,
num_pages: usize,
alignment: usize,
kind: UsageKind,
) -> AllocResult<usize>
pub fn alloc_pages( &self, num_pages: usize, alignment: usize, kind: UsageKind, ) -> AllocResult<usize>
Allocates contiguous pages by allocating page-aligned bytes from TLSF.
Sourcepub fn alloc_dma32_pages(
&self,
_num_pages: usize,
_alignment: usize,
_kind: UsageKind,
) -> AllocResult<usize>
pub fn alloc_dma32_pages( &self, _num_pages: usize, _alignment: usize, _kind: UsageKind, ) -> AllocResult<usize>
Allocates contiguous low-memory pages (physical address < 4 GiB).
Sourcepub fn alloc_pages_at(
&self,
_start: usize,
_num_pages: usize,
_alignment: usize,
_kind: UsageKind,
) -> AllocResult<usize>
pub fn alloc_pages_at( &self, _start: usize, _num_pages: usize, _alignment: usize, _kind: UsageKind, ) -> AllocResult<usize>
Allocates contiguous pages starting from the given address.
Sourcepub fn dealloc_pages(&self, pos: usize, num_pages: usize, kind: UsageKind)
pub fn dealloc_pages(&self, pos: usize, num_pages: usize, kind: UsageKind)
Gives back the allocated pages.
Sourcepub fn used_bytes(&self) -> usize
pub fn used_bytes(&self) -> usize
Returns the number of allocated bytes.
Sourcepub fn available_bytes(&self) -> usize
pub fn available_bytes(&self) -> usize
Returns the number of available bytes.
Sourcepub fn used_pages(&self) -> usize
pub fn used_pages(&self) -> usize
Returns the number of allocated pages.
Sourcepub fn available_pages(&self) -> usize
pub fn available_pages(&self) -> usize
Returns the number of available pages.
Trait Implementations§
Source§impl AllocatorOps for GlobalAllocator
impl AllocatorOps for GlobalAllocator
Source§fn init(&self, start_vaddr: usize, size: usize) -> AllocResult
fn init(&self, start_vaddr: usize, size: usize) -> AllocResult
Initializes the allocator with the given region.
Source§fn add_memory(&self, start_vaddr: usize, size: usize) -> AllocResult
fn add_memory(&self, start_vaddr: usize, size: usize) -> AllocResult
Adds an extra memory region to the allocator.
Source§fn alloc_pages(
&self,
num_pages: usize,
alignment: usize,
kind: UsageKind,
) -> AllocResult<usize>
fn alloc_pages( &self, num_pages: usize, alignment: usize, kind: UsageKind, ) -> AllocResult<usize>
Allocates contiguous pages. Read more
Source§fn alloc_dma32_pages(
&self,
num_pages: usize,
alignment: usize,
kind: UsageKind,
) -> AllocResult<usize>
fn alloc_dma32_pages( &self, num_pages: usize, alignment: usize, kind: UsageKind, ) -> AllocResult<usize>
Allocates contiguous DMA32 pages. Read more
Source§fn alloc_pages_at(
&self,
start: usize,
num_pages: usize,
alignment: usize,
kind: UsageKind,
) -> AllocResult<usize>
fn alloc_pages_at( &self, start: usize, num_pages: usize, alignment: usize, kind: UsageKind, ) -> AllocResult<usize>
Allocates contiguous pages starting from the given address. Read more
Source§fn dealloc_pages(&self, pos: usize, num_pages: usize, kind: UsageKind)
fn dealloc_pages(&self, pos: usize, num_pages: usize, kind: UsageKind)
Deallocates a prior page allocation.
Source§fn used_bytes(&self) -> usize
fn used_bytes(&self) -> usize
Returns used byte count.
Source§fn available_bytes(&self) -> usize
fn available_bytes(&self) -> usize
Returns available byte count.
Source§fn used_pages(&self) -> usize
fn used_pages(&self) -> usize
Returns used page count.
Source§fn available_pages(&self) -> usize
fn available_pages(&self) -> usize
Returns available page count.
Source§impl Default for GlobalAllocator
impl Default for GlobalAllocator
Source§impl GlobalAlloc for GlobalAllocator
impl GlobalAlloc for GlobalAllocator
Source§unsafe fn alloc(&self, layout: Layout) -> *mut u8
unsafe fn alloc(&self, layout: Layout) -> *mut u8
Allocates memory as described by the given
layout. Read moreAuto Trait Implementations§
impl !Freeze for GlobalAllocator
impl !RefUnwindSafe for GlobalAllocator
impl Send for GlobalAllocator
impl Sync for GlobalAllocator
impl Unpin for GlobalAllocator
impl UnsafeUnpin for GlobalAllocator
impl UnwindSafe for GlobalAllocator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more