[−][src]Struct basic_allocator::blocklist::FreeBlock
A FreeBlock
is a wrapper around a pointer to a freed block to be
maintained in a BlockList
.
Invariants are enforced by / inherited from the NonNull strict.
Note that this is very similar to Box, except that it doesn't assume a heap or memory allocator, so it doesn't implement Clone or Drop, and it also has a 'next'.
Implementations
impl FreeBlock
[src]
#[must_use]pub unsafe fn from_raw(
ptr: NonNull<u8>,
next: Option<FreeBlock>,
size: usize
) -> FreeBlock
[src]
ptr: NonNull<u8>,
next: Option<FreeBlock>,
size: usize
) -> FreeBlock
Construct a FreeBlock
from raw parts: a freed memory block at ptr
of
size size
. This will also write the header appropriately.
Safety
This is unsafe because its manipulating raw, freed memory.
To use this safely, ptr
must point to memory of size size
not in use
by or accessible by any program logic.
Further safety constraints are enforced by the invariants of BlockList
.
pub fn as_slice(&self) -> &[u8]
[src]
Get the memory covered by this block as a slice.
pub fn as_range(&self) -> Range<*const u8>
[src]
Get the pointer range covered by this block.
#[must_use]pub fn decompose(self) -> (Range<NonNull<u8>>, Option<FreeBlock>)
[src]
Consume this block and return the range of memory covered, and the next block in the list.
pub fn size(&self) -> usize
[src]
The size of the block, in bytes.
pub fn header_view(&self) -> &FreeHeader
[src]
An immutable pointer to the header
pub unsafe fn header_mut(&mut self) -> &mut FreeHeader
[src]
Get a mutable view of the header.
Safety
This method is unsafe because it allows modifying the size or pointer of a free block in safe code, which could lead to corruption.
#[must_use]pub fn pop_next(&mut self) -> Option<FreeBlock>
[src]
Remove the block after this one from the linked list, and return a pointer to that block and its size.
As is required in a linked list, this will set self.next = next.next.
If there is no next, returns (None, 0).
pub fn insert(&mut self, block: FreeBlock)
[src]
Insert a new element, after this one, maintaining linked list invariants.
block
must have no next
, or an assertion will fail.
pub fn insert_merge(&mut self, block: FreeBlock) -> usize
[src]
Insert a new element, after this one, maintaining linked list invariants and merging with either this item and/or the next, depending on adjacency.
block.next()
must be null, or an assertion will fail.
pub fn split(&mut self, size: usize) -> Range<NonNull<u8>>
[src]
Split off part of this FreeBlock, and return a pointer to the split off data.
The returned pointer is to a region of size 'size' that is no longer considered free.
Panics if 'size' is greater than this block's size - HEADER_SIZE, as there is no way to split off a chunk that large while leaving behind a FreeBlock with an intact header.
pub fn try_merge_next(&mut self) -> bool
[src]
Attempt to merge this block with the next.
If the next block exaists, is adjacent, and exists directly after this block, the two will merge and this will return True; otherwise, this will return False.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,