libtcmalloc_sys/
lib.rs

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