purpleprotocol / mimalloc_rust

A Rust wrapper over Microsoft's MiMalloc memory allocator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can't allocate memory with more than 2mb alignment

XiangpengHao opened this issue · comments

It seems that this crate can't allocate memory with more than 2mb alignment. Not sure if this error is from mimalloc itself or somewhere else.

To reproduce

use mimalloc::MiMalloc;

#[global_allocator]
static GLOBAL: MiMalloc = MiMalloc;

#[cfg(test)]
mod tests {

    #[test]
    fn wont_work() {
        let alloc_size = 2 * 1024 * 1024;
        let layout = std::alloc::Layout::from_size_align(alloc_size, alloc_size).unwrap();
        let alloc = unsafe { std::alloc::alloc_zeroed(layout) };
        assert!(!alloc.is_null());
    }

    #[test]
    fn it_works() {
        let alloc_size = 2 * 1024 * 1024;
        let layout = std::alloc::Layout::from_size_align(alloc_size, alloc_size / 2).unwrap();
        let alloc = unsafe { std::alloc::alloc_zeroed(layout) };
        assert!(!alloc.is_null());
    }
}

Seems like an upstream bug. We just forward to its implementation.

I think this was fixed with 3a94859, I can't reproduce this after that commit.