Vendored version of libc_alloc from crates.io
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Daniel Prilik 763cead9a7 release 1.0.7
2024-03-19 08:44:01 -07:00
src Added posix_memalign()-based MacOS support, updated README.md and bumped version. (#8) 2024-03-19 08:43:22 -07:00
.gitignore release 1.0.0 2020-04-23 19:52:30 -04:00
Cargo.toml release 1.0.7 2024-03-19 08:44:01 -07:00
LICENSE add license + release 1.0.4 2022-11-11 14:00:33 -08:00
README.md Added posix_memalign()-based MacOS support, updated README.md and bumped version. (#8) 2024-03-19 08:43:22 -07:00
rustfmt.toml release 1.0.0 2020-04-23 19:52:30 -04:00

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.