@@ -6,18 +6,47 @@ use std::{
66 thread,
77} ;
88
9- #[ cfg( feature = "jemalloc" ) ]
10- use jemallocator:: Jemalloc ;
11-
129#[ cfg( feature = "dh" ) ]
1310use dhat:: { Dhat , DhatAlloc } ;
1411
1512use num_format:: { Locale , ToFormattedString } ;
1613use rand:: { thread_rng, Rng } ;
1714
18- #[ global_allocator]
1915#[ cfg( feature = "jemalloc" ) ]
20- static ALLOCATOR : Jemalloc = Jemalloc ;
16+ mod alloc {
17+ use std:: alloc:: Layout ;
18+ use jemallocator:: Jemalloc ;
19+
20+ #[ global_allocator]
21+ static ALLOCATOR : Jemalloc = Jemalloc ;
22+ }
23+
24+ #[ cfg( feature = "memshred" ) ]
25+ mod alloc {
26+ use std:: alloc:: { System , Layout } ;
27+
28+ #[ global_allocator]
29+ static ALLOCATOR : Alloc = Alloc ;
30+
31+ #[ derive( Default , Debug , Clone , Copy ) ]
32+ struct Alloc ;
33+
34+ unsafe impl std:: alloc:: GlobalAlloc for Alloc {
35+ unsafe fn alloc ( & self , layout : Layout ) -> * mut u8 {
36+ let ret = System . alloc ( layout) ;
37+ assert_ne ! ( ret, std:: ptr:: null_mut( ) ) ;
38+ std:: ptr:: write_bytes ( ret, 0xa1 , layout. size ( ) ) ;
39+ ret
40+ }
41+
42+ unsafe fn dealloc ( & self , ptr : * mut u8 , layout : Layout ) {
43+ std:: ptr:: write_bytes ( ptr, 0xde , layout. size ( ) ) ;
44+ System . dealloc ( ptr, layout)
45+
46+ }
47+ }
48+ }
49+
2150
2251#[ global_allocator]
2352#[ cfg( feature = "dh" ) ]
0 commit comments