#memory-allocator #allocation #free #global-allocator #polymorph #locked-allocator

nightly polymorph-allocator

A simple memory allocator

7 releases (4 stable)

1.2.0 Nov 16, 2020
1.1.0 May 21, 2020
1.0.0 Apr 21, 2020
0.1.0 Oct 29, 2019

#445 in Memory management

MIT license

32KB
618 lines

polymorph-allocator

A simple Rust memory allocator, designed for polymorphOS.

This crate takes heavy inspiration from awooOS/dmm, a simple C memory allocator for bare-metal uses.

In it's current state, polymorph-allocator is usable, however it is likely to be slow for lots of small allocations. This is an artifact of it's design - every allocation requires iterating through the entire list of allocated chunks until a free chunk is found.

The next major release of polymorph-allocator is planned to completely change how the allocation works, which will improve it's speed, but also it's complexity. The current version of polymorph-allocator is rather simple to understand, and so it could be good as a learning tool. Who knows.

Usage

use polymorph_allocator::LockedAllocator;

#[global_allocator]
pub static ALLOCATOR: LockedAllocator = LockedAllocator::empty();

fn main() {
    // For a 32MB heap starting at 1MB in RAM:
    ALLOCATOR.lock().add_region(0x100000, 0x2000000);
}

License

polymorph-allocator is licensed under the MIT License, the same license as the rest of polymorphOS.

You can find this license in the LICENSE file in the top level of this repository.

Dependencies

~245KB