#![cfg(target_os = "linux")]
use super::PlatformImpl;
use nstd_core::def::NSTDAny;
pub struct PlatformAlloc;
impl PlatformImpl for PlatformAlloc {
#[inline]
unsafe fn allocate(size: usize) -> NSTDAny {
libc::malloc(size)
}
#[inline]
unsafe fn allocate_zeroed(size: usize) -> NSTDAny {
const BYTE_SIZE: usize = std::mem::size_of::<u8>();
libc::calloc(size, BYTE_SIZE)
}
unsafe fn reallocate(ptr: *mut NSTDAny, _: usize, new_size: usize) -> i32 {
let new_mem = libc::realloc(*ptr, new_size);
match new_mem.is_null() {
false => {
*ptr = new_mem;
0
}
true => 1,
}
}
#[inline]
unsafe fn deallocate(ptr: *mut NSTDAny, _: usize) -> i32 {
libc::free(*ptr);
*ptr = std::ptr::null_mut();
0
}
}