I have a library written in C++ that has APIs to transfer bulk data, both via copy and move semantics. For ex. one of the function signature looks like this:
template <
typename ITERATOR,
typename TYPE = typename std::iterator_traits<ITERATOR>::value_type>
void appendData(std::size_t columnIndex,
ITERATOR begin,
ITERATOR end);
A caller can pass in an iterator to a data structure like a std::vector
and this method will append the data starting from 'begin' up to but not including the 'end' iterator. The caller can also pass in a std::move_iterator
instead of a regular iterator, and the data would be moved into the internal structures instead of being copied. The recommendation to the users of this library is to pass in a std::move_iterator
for efficiency reasons.
I want to access this library from Java code (possibly via JNI) and use this interface to transfer data. The question is how do I transfer ownership of a buffer of data that was allocated inside Java to the C++ side so that the Java allocated buffer of data is later freed in C++?
I thought about using apache arrow as the data transfer mechanism, but again the ownership of the arrow structures still rests with the (Java) code that allocated these structures if I am not wrong.