3 ms·
I find `ccall` and especially `@ccall` easy to use, but thankfully haven't spent much time wrapping C libraries so I'd consider myself far from an expert in the
by celrod 4y ago
I find `ccall` and especially `@ccall` easy to use, but thankfully haven't spent much time wrapping C libraries so I'd consider myself far from an expert in the matter.
Creating mutable structs and `GC.@preserve`ing them is an effective means of getting stack allocated memory, so long as the structs do not escape.
E.g., I occasionally follow this approach:
mem = Ref{NTuple{32,Float64}}()
GC.@preserve mem begin
p = Base.unsafe_convert(Ptr{Float64}, mem)
# do things with p, e.g. pass it to a C library
end
- deleted 4y ago[deleted]