@@ -6,23 +6,26 @@ 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+ // across targets. `ArenaHeapItem` embeds a pointer, so its size varies
13+ // with pointer width, compute the arena size from `size_of` instead
14+ // of using a hardcoded byte value.
15+ const BATCH : usize = 32 ;
16+ const ARENA_SIZE : usize = BATCH * core:: mem:: size_of :: < ArenaHeapItem < i32 > > ( ) ;
1417
15- // An Arena heap object has an overhead of 4-8 bytes, depending on the platform
18+ let mut allocator = ArenaAllocator :: default ( ) . with_arena_size ( ARENA_SIZE ) ;
1619
1720 let mut first_region = Vec :: default ( ) ;
18- for i in 0 ..32 {
21+ for i in 0 ..32_i32 {
1922 let value = allocator. try_alloc ( i) . unwrap ( ) ;
2023 first_region. push ( value. as_ptr ( ) ) ;
2124 }
2225 assert_eq ! ( allocator. arenas_len( ) , 1 ) ;
2326
2427 let mut second_region = Vec :: default ( ) ;
25- for i in 0 ..32 {
28+ for i in 0 ..32_i32 {
2629 let value = allocator. try_alloc ( i) . unwrap ( ) ;
2730 second_region. push ( value. as_ptr ( ) ) ;
2831 }
@@ -31,7 +34,8 @@ fn alloc_dealloc() {
3134 // Drop all the items in the first region
3235 manual_drop ( first_region) ;
3336
34- // Drop dead pages
37+ // Drop dead pages, only the first arena is fully dropped, the second
38+ // arena remains live because none of its items have been marked dropped.
3539 allocator. drop_dead_arenas ( ) ;
3640
3741 assert_eq ! ( allocator. arenas_len( ) , 1 ) ;
0 commit comments