alloc_madvise/lib.rs
1//! # alloc-madvise
2//!
3//! Rust-aligned-allocations provides aligned memory allocation utilities for Rust.
4//!
5//! This crate offers functionality to allocate and manage memory with specific alignment requirements.
6//! The main features include:
7//!
8//! - [`Memory`] - A safe wrapper around aligned memory allocations
9//! - [`AllocationError`] - Error type for memory allocation failures
10//!
11//! # Example
12//!
13//! ```
14//! use alloc_madvise::{Memory, AllocationError};
15//!
16//! fn main() -> Result<(), AllocationError> {
17//! // Allocate 1024 bytes aligned to 64 bytes
18//! const SIZE: usize = 1024;
19//! const SEQUENTIAL: bool = true;
20//! const CLEAR: bool = true;
21//! let memory = Memory::allocate(SIZE, SEQUENTIAL, CLEAR)?;
22//!
23//! // Use the allocated memory...
24//! assert_ne!(memory.as_ptr(), std::ptr::null_mut());
25//! assert_eq!((memory.as_ptr() as usize) % 64, 0);
26//! assert_eq!(memory.len(), SIZE);
27//! assert!(!memory.is_empty());
28//!
29//! // Memory is automatically freed when dropped
30//! Ok(())
31//! }
32//! ```
33//!
34//! # Features
35//!
36//! - `ffi`: Enables FFI bindings for C interoperability (disabled by default)
37#![allow(unsafe_code)]
38
39#[cfg(feature = "ffi")]
40mod ffi;
41
42mod alignment;
43mod alloc_free;
44mod alloc_result;
45mod memory;
46
47pub use alloc_result::AllocationError;
48pub use memory::Memory;