Skip to content
Merged
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
10 changes: 6 additions & 4 deletions crates/j2k-alloc-probe/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const KIB: u64 = 1024;
static PROBE_POOL: OnceLock<ThreadPool> = OnceLock::new();

fn main() {
probe_pool().broadcast(|_| {});

// Keep the Rayon pool uninitialized while exact allocator self-tests run.
// The process-wide meter intentionally records unrelated worker activity.
let cases: &[(&str, fn())] = &[
(
"harness_counts_allocation_and_deallocation",
Expand Down Expand Up @@ -89,15 +89,17 @@ fn main() {
}

fn harness_counts_allocation_and_deallocation() {
let (allocation, retained) = measure(|| black_box(Box::new([0_u8; 4096])));
// Allocate the backing storage directly. In debug builds, constructing a
// large array inside `Box::new` can use an additional temporary allocation.
let (allocation, retained) = measure(|| black_box(Box::<[u8]>::new_uninit_slice(4096)));
assert_eq!(retained.allocations, 1);
assert_eq!(retained.reallocations, 0);
assert_eq!(retained.deallocations, 0);
assert!(retained.requested_bytes >= 4096);
drop(allocation);

let ((), released) = measure(|| {
drop(black_box(Box::new([0_u8; 4096])));
drop(black_box(Box::<[u8]>::new_uninit_slice(4096)));
});
assert_eq!(released.allocations, 1);
assert_eq!(released.reallocations, 0);
Expand Down