libtcmalloc_sys/
lib.rs

1#![no_std]
2
3#[cfg(feature = "extension")]
4mod extension;
5
6#[cfg(feature = "extension")]
7pub use extension::*;
8
9unsafe extern "C" {
10    /// Allocate `size` bytes aligned by `align`.
11    ///
12    /// Return a pointer to the allocated memory or null if out of memory.
13    ///
14    /// Returns a unique pointer if called with `size` 0.
15    pub fn TCMallocInternalAlignedAlloc(
16        align: libc::size_t,
17        size: libc::size_t,
18    ) -> *mut core::ffi::c_void;
19
20    /// Free previously allocated memory.
21    ///
22    /// The pointer `ptr` must have been allocated before (or be null).
23    ///
24    /// The `align` and `size` must match the ones used to allocate `ptr`.
25    pub fn TCMallocInternalFreeAlignedSized(
26        ptr: *mut core::ffi::c_void,
27        align: libc::size_t,
28        size: libc::size_t,
29    );
30}
31
32#[cfg(test)]
33mod tests {
34    use super::*;
35
36    #[test]
37    fn it_frees_memory_malloc() {
38        let ptr = unsafe { TCMallocInternalAlignedAlloc(8, 8) } as *mut u8;
39        unsafe { TCMallocInternalFreeAlignedSized(ptr as *mut libc::c_void, 8, 8) };
40    }
41}