nstd_alloc/
lib.rs

1pub mod heap;
2#[cfg(feature = "deps")]
3pub mod deps {
4    #[cfg(target_os = "macos")]
5    pub use core_foundation;
6    #[cfg(target_os = "linux")]
7    pub use libc;
8    pub use nstd_core;
9    #[cfg(target_os = "windows")]
10    pub use windows;
11}
12mod platform;
13use nstd_core::def::NSTDAny;
14use platform::*;
15
16/// Allocates a new memory block.
17/// Parameters:
18///     `const NSTDUSize size` - Number of bytes to allocate.
19/// Returns: `NSTDAny ptr` - The new memory block.
20#[inline]
21#[cfg_attr(feature = "clib", no_mangle)]
22pub unsafe extern "C" fn nstd_alloc_allocate(size: usize) -> NSTDAny {
23    PlatformAlloc::allocate(size)
24}
25
26/// Allocates a new memory block with all bytes set to 0.
27/// Parameters:
28///     `const NSTDUSize size` - Number of bytes to allocate.
29/// Returns: `NSTDAny ptr` - The new memory block.
30#[inline]
31#[cfg_attr(feature = "clib", no_mangle)]
32pub unsafe extern "C" fn nstd_alloc_allocate_zeroed(size: usize) -> NSTDAny {
33    PlatformAlloc::allocate_zeroed(size)
34}
35
36/// Reallocates a memory block.
37/// Parameters:
38///     `NSTDAny *const ptr` - Pointer to the memory block.
39///     `const NSTDUSize size` - The current size of the memory block.
40///     `const NSTDUSize new_size` - The new size of the memory block.
41/// Returns: `NSTDInt32 errc` - Nonzero on error.
42#[inline]
43#[cfg_attr(feature = "clib", no_mangle)]
44pub unsafe extern "C" fn nstd_alloc_reallocate(
45    ptr: *mut NSTDAny,
46    size: usize,
47    new_size: usize,
48) -> i32 {
49    PlatformAlloc::reallocate(ptr, size, new_size)
50}
51
52/// Deallocates a memory block.
53/// Parameters:
54///     `NSTDAny *const ptr` - Pointer to the memory block.
55///     `const NSTDUSize size` - Number of bytes to deallocate.
56/// Returns: `NSTDInt32 errc` - Nonzero on error.
57#[inline]
58#[cfg_attr(feature = "clib", no_mangle)]
59pub unsafe extern "C" fn nstd_alloc_deallocate(ptr: *mut NSTDAny, size: usize) -> i32 {
60    PlatformAlloc::deallocate(ptr, size)
61}