#![cfg_attr(feature = "alloc_trait", feature(allocator_api))]
use tikv_jemallocator::Jemalloc;
#[global_allocator]
static A: Jemalloc = Jemalloc;
#[test]
#[cfg(feature = "alloc_trait")]
fn shrink_in_place() {
unsafe {
use std::alloc::{Alloc, Layout};
let orig_sz = 10 * 4096;
let orig_l = Layout::from_size_align(orig_sz, 1).unwrap();
let ptr = Jemalloc.alloc(orig_l).unwrap();
let new_sz = 1;
if let Ok(()) = Jemalloc.shrink_in_place(ptr, orig_l, new_sz) {
let new_l = Layout::from_size_align(new_sz, 1).unwrap();
Jemalloc.dealloc(ptr, new_l);
} else {
Jemalloc.dealloc(ptr, orig_l);
}
}
}