diff --git a/src/noalloc.rs b/src/noalloc.rs index a6ffaf2..90b380e 100644 --- a/src/noalloc.rs +++ b/src/noalloc.rs @@ -58,7 +58,7 @@ impl AtomAlloc { } else { // take and subtract head self.head = Some(index - 1); - self.atoms[index - 1].take() + self.atoms[index].take() } } else { None diff --git a/src/tests.rs b/src/tests.rs index 9a039cb..8d537c1 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -29,4 +29,36 @@ fn noalloc() { alloc.defragment(); // [(1024, 64)...] assert_eq!(alloc.atoms[0], Some(Atom { start: 1024, frame_count: 64 })); assert_eq!(alloc.head, Some(0)); +} + +#[test] +fn noalloc_irl() { + let mut alloc: AtomAlloc<1024, 4096> = AtomAlloc::default(); + + alloc.add_memory(0x51000, 2); + alloc.add_memory(0x54000, 72); + alloc.add_memory(0x100000, 259887); + alloc.add_memory(0x3f925000, 1); + alloc.add_memory(0x3fed3000, 15); + + let mut first = alloc.allocate(1); + if first.is_none() { + alloc.defragment(); + first = alloc.allocate(1); + } + assert!(first.is_some()); + + let mut second = alloc.allocate(1); + if second.is_none() { + alloc.defragment(); + second = alloc.allocate(1); + } + assert!(second.is_some()); + + let mut third = alloc.allocate(1); + if third.is_none() { + alloc.defragment(); + third = alloc.allocate(1); + } + assert!(third.is_some()); } \ No newline at end of file