@@ -6,23 +6,27 @@ use crate::alloc::arena2::ArenaHeapItem;
66
77use super :: ArenaAllocator ;
88
9- // TODO: Needs testing on a 32bit system
109#[ test]
1110fn alloc_dealloc ( ) {
12- // Let's just allocate with a half a Kb per arena
13- let mut allocator = ArenaAllocator :: default ( ) . with_arena_size ( 512 ) ;
11+ // Ensure the arena holds exactly `BATCH` `ArenaHeapItem<i32>` values.
12+ //
13+ // Note: we calculate this with `size_of` because ArenaHeapItem<i32> is
14+ // smaller on 32-bit targets than on 64-bit targets, so a fixed byte size
15+ // would not test the same item count on both.
16+ const BATCH : usize = 32 ;
17+ const ARENA_SIZE : usize = BATCH * core:: mem:: size_of :: < ArenaHeapItem < i32 > > ( ) ;
1418
15- // An Arena heap object has an overhead of 4-8 bytes, depending on the platform
19+ let mut allocator = ArenaAllocator :: default ( ) . with_arena_size ( ARENA_SIZE ) ;
1620
1721 let mut first_region = Vec :: default ( ) ;
18- for i in 0 ..32 {
22+ for i in 0 ..32_i32 {
1923 let value = allocator. try_alloc ( i) . unwrap ( ) ;
2024 first_region. push ( value. as_ptr ( ) ) ;
2125 }
2226 assert_eq ! ( allocator. arenas_len( ) , 1 ) ;
2327
2428 let mut second_region = Vec :: default ( ) ;
25- for i in 0 ..32 {
29+ for i in 0 ..32_i32 {
2630 let value = allocator. try_alloc ( i) . unwrap ( ) ;
2731 second_region. push ( value. as_ptr ( ) ) ;
2832 }
@@ -31,7 +35,8 @@ fn alloc_dealloc() {
3135 // Drop all the items in the first region
3236 manual_drop ( first_region) ;
3337
34- // Drop dead pages
38+ // Drop dead pages, only the first arena is fully dropped, the second
39+ // arena remains live because none of its items have been marked dropped.
3540 allocator. drop_dead_arenas ( ) ;
3641
3742 assert_eq ! ( allocator. arenas_len( ) , 1 ) ;
0 commit comments