brenhinkeller / StaticTools.jl

Enabling StaticCompiler.jl-based compilation of (some) Julia code to standalone native binaries by avoiding GC allocations and llvmcall-ing all the things!
MIT License
168 stars 12 forks source link

Compose with ArrayAllocators.jl #18

Open mkitti opened 2 years ago

mkitti commented 2 years ago

I am interested in exploring how ArrayAllocators.jl may compose with MallocArray.

Essentially, the main task of an AbstractArrayAllocator is to allocate memory safely and return a pointer via the method ArrayAllocators.allocate. We should be able to take that pointer and use it in a MallocArray.

One way of setting that up would be via Base.unsafe_wrap.

brenhinkeller commented 2 years ago

Oh, that could be cool!

A MallocArray is basically just a thin wrapper around a pointer, so if you have a pointer you can make a MallocArray from it with just MallocArray{T}(ptr, size...)

The main catch might be making an AbstractArrayAllocator that is StaticCompiler-able? But if that can be done then wrapping the pointer is easy enough.

mkitti commented 2 years ago

We need either a Ptr wrapper or a type parameter to allow for alternate implementations of free when Libc.free might not apply.

brenhinkeller commented 2 years ago

I think adding a new type parameter could make sense -- that may actually help answer a related question about what type views should return (some discussion at https://julialang.zulipchat.com/#narrow/stream/137791-general/topic/StaticTools.2Ejl/near/291368732)