#libc #allocator #malloc #linker #codebase #memalign

no-std libc_alloc

A simple global allocator which hooks into libc's malloc/free

8 stable releases

1.0.7 Mar 19, 2024
1.0.6 Jan 6, 2024
1.0.5 Jul 25, 2023
1.0.4 Nov 11, 2022
1.0.2 Apr 24, 2020

#40 in FFI

Download history 4104/week @ 2024-09-04 3485/week @ 2024-09-11 3298/week @ 2024-09-18 3623/week @ 2024-09-25 2914/week @ 2024-10-02 3315/week @ 2024-10-09 3435/week @ 2024-10-16 2875/week @ 2024-10-23 3344/week @ 2024-10-30 3749/week @ 2024-11-06 3315/week @ 2024-11-13 2479/week @ 2024-11-20 2238/week @ 2024-11-27 2462/week @ 2024-12-04 3853/week @ 2024-12-11 3060/week @ 2024-12-18

11,979 downloads per month
Used in 3 crates

MIT license

8KB
101 lines

libc_alloc

A simple global allocator for Rust which hooks into libc functions. Useful when linking no_std + alloc code into existing C codebases.

On Unix-like OSs, use memalign for allocations, and free for deallocations.

On macOS, use posix_memalign for allocations, and free for deallocations.

On Windows, use native _aligned_malloc for allocations, _aligned_realloc for reallocations, and _aligned_free for deallocations.

Example

use libc_alloc::LibcAlloc;

#[global_allocator]
static ALLOCATOR: LibcAlloc = LibcAlloc;

Alternatively, with the global Cargo feature, the crate only needs to be pulled in:

extern crate libc_alloc;

Project Status

Given how dead-simple this crate is, I doubt it will need to be updated very often.

Please file an issue and/or open a PR if you spot a bug / if something stops working.

No runtime deps

Features