Repository navigation
Safety fixes
- Make
allocanunsafe fnand document its nonzero-layout precondition, fixing #7. - Support zero-sized types in
Box, including aligned types and types with destructors, without allocating hugepage memory. - Initialize boxed values through raw pointers without first creating references to uninitialized values.
- Return null for requested alignments larger than the system's default hugepage size.
- Correct examples and tests to borrow hugepage-backed strings instead of transferring their memory to a standard
String.
Simplification
- Remove the private stateless allocator type, singleton,
GlobalAllocimplementation, and forwarding helpers.Boxuses the exported allocation functions directly.
Migration from v0.1.1
Calls to alloc now require an unsafe block. The layout size must be nonzero; check for allocation failure before accessing the returned pointer. dealloc remains unsafe and requires the original pointer and layout.
let layout = std::alloc::Layout::new::<u64>();
let ptr = unsafe { hugepage_rs::alloc(layout) };
if !ptr.is_null() {
unsafe {
ptr.cast::<u64>().write(42);
hugepage_rs::dealloc(ptr, layout);
}
}Box::new(()) is now supported. Linux hugepages must still be configured for nonzero allocations.
Full changes: #8