[][src]Struct buddies::RawBuddies

pub struct RawBuddies<T> { /* fields omitted */ }

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 0s (i.e falses).

pub fn can_allocate(&self, n: usize) -> bool[src]

Checks if a block of size 2^n Ts 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 Ts.

Note for safe shells: You want to convert the reference to a pointer so that multiple allocations can exist simultaneously (or work around using Rc somehow).

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]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]