>Could you maybe reformulate your
question and provide more information about the constraints that
you are facing?
I need to pass vector of structs to Java using callback (pure virtual function).
On Java side, inside a callback I add Pointers of these structs to Java container. Later on, I remove them from container indepedently at different times and want them to be garbage collected and deallocated independently.
I decided to add template function that takes a reference and move constucts a new value out of it:
template<typename T>
inline T moveConstruct(T& other) { return std::move(other); }
And then define it for types I need using Info() and use it in Java when getting elements from vector. I'm not sure if it is the best solution with JavaCPP, but it works.
I also tried to use FooPointer with @StdVector instead of FooVector wrapper class (which creates a number of additional methods that I don't need) but discovered that it always creates new instance of my vector on heap before passing it to Java, which is unneccessary in my case (since I move values out of it immediately using moveConstruct). FooVector, on the other hand, passes pointer of existing vector if I pass it to callback as pointer or reference. Is there a way to do the same with @StdVector?
среда, 26 мая 2021 г. в 03:02:56 UTC+3, Samuel Audet: