retry_alloc 0.1.0

A global allocator wrapper that will retry failed allocations.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use std::alloc::{Layout, System};

use stats_alloc::StatsAlloc;

use crate::RetryAlloc;

static RETRY: RetryAlloc = RetryAlloc::new(System);
#[global_allocator]
static GLOBAL: StatsAlloc<&RetryAlloc> = StatsAlloc::new(&RETRY);

#[test]
fn test_fail() {
    let p = unsafe { std::alloc::alloc(Layout::array::<u32>(isize::MAX as usize / 4).unwrap()) };
    assert!(p.is_null());
    assert!(RETRY.number_of_retries() > 0);
}