#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

#38 in FFI

Download history 3100/week @ 2024-07-25 2614/week @ 2024-08-01 3353/week @ 2024-08-08 3881/week @ 2024-08-15 3212/week @ 2024-08-22 2941/week @ 2024-08-29 4286/week @ 2024-09-05 3487/week @ 2024-09-12 3126/week @ 2024-09-19 3603/week @ 2024-09-26 2750/week @ 2024-10-03 3497/week @ 2024-10-10 3383/week @ 2024-10-17 2810/week @ 2024-10-24 3712/week @ 2024-10-31 3685/week @ 2024-11-07

14,230 downloads per month
Used in 2 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