Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "allocator"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
authors = ["Yuekai Jia <[email protected]>"]
description = "Various allocator algorithms in a unified interface"
Expand Down
1 change: 1 addition & 0 deletions benches/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const POOL_SIZE: usize = 1024 * 1024 * 128;

fn vec_push(n: usize, alloc: &(impl Allocator + Clone)) {
let mut v: Vec<u32, _> = Vec::new_in(alloc.clone());
#[allow(clippy::same_item_push)]
for _ in 0..n {
v.push(0xdead_beef);
}
Expand Down
6 changes: 6 additions & 0 deletions src/bitmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ impl<const PAGE_SIZE: usize> BitmapPageAllocator<PAGE_SIZE> {
}
}

impl<const PAGE_SIZE: usize> Default for BitmapPageAllocator<PAGE_SIZE> {
fn default() -> Self {
Self::new()
}
}

impl<const PAGE_SIZE: usize> BaseAllocator for BitmapPageAllocator<PAGE_SIZE> {
fn init(&mut self, start: usize, size: usize) {
assert!(PAGE_SIZE.is_power_of_two());
Expand Down
6 changes: 6 additions & 0 deletions src/buddy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ impl BuddyByteAllocator {
}
}

impl Default for BuddyByteAllocator {
fn default() -> Self {
Self::new()
}
}

impl BaseAllocator for BuddyByteAllocator {
fn init(&mut self, start: usize, size: usize) {
unsafe { self.inner.init(start, size) };
Expand Down
6 changes: 6 additions & 0 deletions src/slab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ impl SlabByteAllocator {
}
}

impl Default for SlabByteAllocator {
fn default() -> Self {
Self::new()
}
}

impl BaseAllocator for SlabByteAllocator {
fn init(&mut self, start: usize, size: usize) {
self.inner = unsafe { Some(Heap::new(start, size)) };
Expand Down
6 changes: 6 additions & 0 deletions src/tlsf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ impl TlsfByteAllocator {
}
}

impl Default for TlsfByteAllocator {
fn default() -> Self {
Self::new()
}
}

impl BaseAllocator for TlsfByteAllocator {
fn init(&mut self, start: usize, size: usize) {
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion tests/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn test_alignment(n: usize, alloc: &(impl Allocator + Clone)) {
let mut rng = rand::thread_rng();
let mut blocks = vec![];
for _ in 0..n {
if rng.gen_ratio(2, 3) || blocks.len() == 0 {
if rng.gen_ratio(2, 3) || blocks.is_empty() {
// insert a block
let size =
((1 << rng.gen_range(0..16)) as f32 * rng.gen_range(1.0..2.0)).round() as usize;
Expand Down