snmalloc icon indicating copy to clipboard operation
snmalloc copied to clipboard

support allocator api

Open SchrodingerZhu opened this issue 4 years ago • 6 comments

export FFIs to enable snmalloc being used as a separate allocator https://doc.rust-lang.org/stable/std/alloc/trait.Allocator.html

SchrodingerZhu avatar Nov 21 '21 11:11 SchrodingerZhu

it there a way to trigger the build again?

SchrodingerZhu avatar Nov 24 '21 14:11 SchrodingerZhu

So on

https://github.com/microsoft/snmalloc/runs/4311202740?check_suite_focus=true

I have a Re-runall checks:

image**

I'll hit it for you. Do you need some help with the Windows tests?

mjp41 avatar Nov 24 '21 14:11 mjp41

Ha, I guess sth interesting is happening on Win. I will have a look later when I can clear some space for MSVC on my PC ;).

SchrodingerZhu avatar Nov 24 '21 14:11 SchrodingerZhu

Running your test gives:

        _STL_ASSERT(_Left == _Right, "containers incompatible for swap");

failing on

  std::swap(cloned, moved);

in void test_allocator_vector()

mjp41 avatar Nov 24 '21 15:11 mjp41

Sure! I am still sorting out the design.

SchrodingerZhu avatar Nov 26 '21 13:11 SchrodingerZhu

@mjp41 @davidchisnall I begin to wonder whether we should only expose sth like sn_rust_grow, sn_rust_shrink.

I wanted to support sth like:

 fn allocator_supports_vector() {
        let allocator = SnAllocator::new();
        let mut vec = std::vec::Vec::new_in(&allocator);
        let mut sum: usize = 0;
        for i in 1..512usize {
            vec.push(i);
            sum += i * i;
        }

        let res = vec.into_iter().flat_map(|x| {
            let mut v = std::vec::Vec::new_in(&allocator);
            for _ in 0..x {
                v.push(x);
            }
            v
        }).sum();

        assert_eq!(sum, res);
    }

But I begin to wonder whether it is a bad decision to let user use a Alloc* instead of make Alloc thread_local.

SchrodingerZhu avatar Dec 04 '21 12:12 SchrodingerZhu