#libc #allocator #malloc #no-std #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

#79 in Embedded development

Download history 2246/week @ 2024-04-01 2559/week @ 2024-04-08 3410/week @ 2024-04-15 2434/week @ 2024-04-22 1669/week @ 2024-04-29 2543/week @ 2024-05-06 1775/week @ 2024-05-13 2318/week @ 2024-05-20 3389/week @ 2024-05-27 3202/week @ 2024-06-03 3880/week @ 2024-06-10 2973/week @ 2024-06-17 3157/week @ 2024-06-24 3094/week @ 2024-07-01 3517/week @ 2024-07-08 3054/week @ 2024-07-15

12,950 downloads per month
Used in icu_capi

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