This is my first question here, so if I’m doing something wrong, please advice me.
Well, in order to make this question I have to briefly introduce my case. I’m developing a NLP library in C++. It’s nothing very original, fancy or revolutionary, but more like an amateur-made-to-learn-copy-a-lot-of-work-of-other-libraries project. Well, a NLP library without a dynamic interface is a little worthless, so I thought about doing it in Julia, a language I have no experience (so I can learn Julia and NLP with the same shot).
For now I’m using Eigen as a primary backend to the CPU part of the library in the C++ side. But I don’t want to wrap and expose Eigen matrixes or tensors to Julia, I want the data to be owned by Julia’s arrays, so users can have all their nice and familiar syntax. So, what I want is to manipulate the Julia arrays directly through the C api. I have looked at the documentation, and that seems totally possible.
What makes me doubt is how to pass from C to Julia:
-> I have seen that I can exclude from Julia memory ownership a Julia array created from C if I pass a 0 to the last boolean argument of jl_ptr_to_array_Xd. Is there a way to switch off the memory ownership of an array that is already owned by the Julia gc system (for example, created with jl_alloc_array_Xd in C or directly in Julia)?
-> How can I construct in Julia code an array that has been allocated directly in C (I imagine I have to return a jl_array_t* pointer from a ccall, but what do I do with this pointer to have a complete Julia array)? Does this array to have the gc option activated? Ccall where only pointers are passed are costly?
-> When I pass a Julia Array to a ccall, the C code receives a jl_array_t* pointer or a pointer to the underlying data structure (similar to calling jl_array_data)?
Thank you in advance for any help