# FrameAllocator in buddy_system_allocator - Rust
A frame allocator that uses buddy system, requiring a global allocator
Keywords: rust, rustlang, rust-lang, FrameAllocator

# Struct buddy_system_allocator::FrameAllocator

source · [−]

    pub struct FrameAllocator { /* private fields */ }

Expand description

A frame allocator that uses buddy system, requiring a global allocator

## Usage

Create a frame allocator and add some frames to it:

    use buddy_system_allocator::*;
    let mut frame = FrameAllocator::new();
    assert!(frame.alloc(1).is_none());

    frame.add_frame(0, 3);
    let num = frame.alloc(1);
    assert_eq!(num, Some(2));
    let num = frame.alloc(2);
    assert_eq!(num, Some(0));

## Implementations

source

### impl FrameAllocator

source

#### pub fn new() -> Self

Create an empty frame allocator

source

#### pub fn add_frame(&mut self, start: usize, end: usize)

Add a range of frame number [start, end) to the allocator

source

#### pub fn insert(&mut self, range: Range<usize>)

Add a range of frame to the allocator

source

#### pub fn alloc(&mut self, count: usize) -> Option<usize>

Alloc a range of frames from the allocator, return the first frame of the allocated range

source

#### pub fn dealloc(&mut self, frame: usize, count: usize)

Dealloc a range of frames [frame, frame+count) from the frame allocator. The range should be exactly the same when it was allocated, as in heap allocator

## Auto Trait Implementations

### impl RefUnwindSafe for FrameAllocator

### impl Send for FrameAllocator

### impl Sync for FrameAllocator

### impl Unpin for FrameAllocator

### impl UnwindSafe for FrameAllocator

## Blanket Implementations

source

### impl<T> Any for T where
T: 'static + ?Sized,

source

#### fn type_id(&self) -> TypeId

Gets the `TypeId` of `self`. Read more

source

### impl<T> Borrow<T> for T where
T: ?Sized,

const: unstable · source

#### fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more

source

### impl<T> BorrowMut<T> for T where
T: ?Sized,

const: unstable · source

#### fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more

source

### impl<T> From<T> for T

const: unstable · source

#### fn from(t: T) -> T

Returns the argument unchanged.

source

### impl<T, U> Into<U> for T where
U: From<T>,

const: unstable · source

#### fn into(self) -> U

Calls `U::from(self)`.

That is, this conversion is whatever the implementation of `From<T> for U` chooses to do.

source

### impl<T, U> TryFrom<U> for T where
U: Into<T>,

#### type Error = Infallible

The type returned in the event of a conversion error.

const: unstable · source

#### fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.

source

### impl<T, U> TryInto<U> for T where
U: TryFrom<T>,

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

The type returned in the event of a conversion error.

const: unstable · source

#### fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.