Skip to content

mimalloc returns non-aligned memory #128

Closed as not planned
Closed as not planned
@emilk

Description

@emilk

I had this code fail (on both Mac and Windows):

#[global_allocator]
static GLOBAL: AccountingAllocator<mimalloc::MiMalloc> =
    AccountingAllocator::new(mimalloc::MiMalloc);

#[repr(C, align(256))]
pub struct BigStruct {}

fn collect() {
    assert_eq!(align_of::<BigStruct>(), 256);
    assert_eq!(size_of::<BigStruct>(), 256);
    let vec: Vec<T> = std::iter::once(BigStruct{}).collect();
    dbg!(vec.as_ptr() as usize % std::mem::align_of::<T>()); // Sometimes prints 64
    let slice = vec.as_slice(); // panics in debug builds because of the unaligned memory
}

Granted, 256 is a very large alignment, but I expect either mimalloc to handle it, or to log a warning, or panic, or similar.
But I don't want it to quietly return unaligned memory.
I cannot find any docs saying there is a limit to the supported alignment.

The standard allocator never fails on the same code.

Maybe related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions