use jemallocator::Jemalloc;
use std::alloc::System;
/// Allocator that doesn't deallocate
struct LeakingAllocator;
unsafe impl std::alloc::GlobalAlloc for LeakingAllocator {
unsafe fn alloc(&self, layout: std::alloc::Layout) -> *mut u8 {
Jemalloc.alloc(layout)
}
unsafe fn dealloc(&self, _ptr: *mut u8, _layout: std::alloc::Layout) {}
}
okaoka::set_multi_global_allocator! {
GlobalAllocator, // Name of our allocator facade
AllocatorTag, // Name of our allocator tag enum
System => System,
Jemalloc => Jemalloc,
Leaking => LeakingAllocator,
}
fn main() {
let mut x = Box::new(10); // Allocated with the default allocator
dbg!(&*x as *const i32);
GlobalAllocator::with(AllocatorTag::Leaking, || {
x = Box::new(20); // Allocated with the leaking allocator
}); // Previous allocator restored
dbg!(&*x as *const i32);
}
-
Notifications
You must be signed in to change notification settings - Fork 2
emi2k01/okaoka
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published