[−][src]Struct buddies::RawBuddies
RawBuddies
: A slightly unsafe buddy allocator.
A small size and no standard library dependency is traded for an unsafe structure. A safe shell can be constructed around this for built-in allocation of resources as well as a safe allocation result.
Methods
impl<T> RawBuddies<T>
[src]
pub unsafe fn new(num: usize, data: *mut T, bits: *mut u8) -> Self
[src]
Creates a new RawBuddies
.
Conditions
data
and bits
are not dropped as long as the instantiation lives.
data
is at least of length 2^num
. It may be uninitialized.
bits
is at least of length 2^num/8
(i.e it holds 2^num
bits). It
must only contain 0
s (i.e false
s).
pub fn can_allocate(&self, n: usize) -> bool
[src]
Checks if a block of size 2^n
T
s can be allocated.
Panics
Panics if the block size is too large (>= buddies
).
pub fn allocate(&mut self, n: usize) -> Option<(*mut T, usize)>
[src]
Allocates a block of size 2^n
T
s.
Note for safe shells: You want to convert the pointer to a slice such that multiple (mutable) slices can be held simultaneously.
Returns the reference as well as the block index (for freeing later).
Panics
Panics if the block size is too large (>= buddies
).
pub fn free(&mut self, n: usize, pos: usize)
[src]
Frees a given block by index and size.
Panics
Panics if the block size is too large (>= buddies
).
Panics if the index is too large (>= 2^(buddies-size-1)
).
Panics if the block was already free (possible double-free).
Auto Trait Implementations
impl<T> !Send for RawBuddies<T>
impl<T> !Sync for RawBuddies<T>
Blanket Implementations
impl<T> From<T> for T
[src]
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> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,