Skip to content

v0.1.2

Latest

Choose a tag to compare

@cppcoffee cppcoffee released this 28 Oct 01:55
· 4 commits to main since this release

Safety fixes

  • Make alloc an unsafe fn and 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, GlobalAlloc implementation, and forwarding helpers. Box uses 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