1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// TODO: arch checks and windows version
extern "C" {
    #[cfg(target_os = "linux")]
    fn aligned_alloc(alignment: usize, size: usize) -> *mut u8;
    #[cfg(target_os = "windows")]
    fn _aligned_malloc(size: usize, alignment: usize) -> *mut u8;
}

#[cfg(target_os = "linux")]
pub fn aligned_malloc(alignment: usize, size: usize) -> *mut u8 {
    unsafe {
        return aligned_alloc(alignment, size);
    }
}

#[cfg(target_os = "windows")]
pub fn aligned_malloc(alignment: usize, size: usize) -> *mut u8 {
    unsafe {
        return _aligned_malloc(size, alignment);
    }
}