File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -404,6 +404,36 @@ impl From<AllocErr> for CollectionAllocErr {
404
404
}
405
405
}
406
406
407
+ // FIXME: docs
408
+ pub unsafe trait GlobalAlloc {
409
+ unsafe fn alloc ( & self , layout : Layout ) -> * mut Void ;
410
+
411
+ unsafe fn dealloc ( & self , ptr : * mut Void , layout : Layout ) ;
412
+
413
+ unsafe fn alloc_zeroed ( & self , layout : Layout ) -> * mut Void {
414
+ let size = layout. size ( ) ;
415
+ let ptr = self . alloc ( layout) ;
416
+ if !ptr. is_null ( ) {
417
+ ptr:: write_bytes ( ptr as * mut u8 , 0 , size) ;
418
+ }
419
+ ptr
420
+ }
421
+
422
+ unsafe fn realloc ( & self , ptr : * mut Void , old_layout : Layout , new_size : usize ) -> * mut Void {
423
+ let new_layout = Layout :: from_size_align_unchecked ( new_size, old_layout. align ( ) ) ;
424
+ let new_ptr = self . alloc ( new_layout) ;
425
+ if !new_ptr. is_null ( ) {
426
+ ptr:: copy_nonoverlapping (
427
+ ptr as * const u8 ,
428
+ new_ptr as * mut u8 ,
429
+ cmp:: min ( old_layout. size ( ) , new_size) ,
430
+ ) ;
431
+ self . dealloc ( ptr, old_layout) ;
432
+ }
433
+ new_ptr
434
+ }
435
+ }
436
+
407
437
/// An implementation of `Alloc` can allocate, reallocate, and
408
438
/// deallocate arbitrary blocks of data described via `Layout`.
409
439
///
You can’t perform that action at this time.
0 commit comments