kostaskougios / cloning

deep clone java objects
Other
591 stars 111 forks source link

Native Objects? #41

Open JLLeitschuh opened 9 years ago

JLLeitschuh commented 9 years ago

Does this library work with native objects. Our project is using https://github.com/bytedeco/javacpp-presets which has native bindings to C++ objects. Will this work for that?

kostaskougios commented 9 years ago

I can't really tell, never tried it. The library uses reflection to find all field members of a class. Then it recursively deep clones them. How do you get a reference to a native object and where do you store it? Is that reference a specific java type?

JLLeitschuh commented 9 years ago

This is an example of what I want to clone: https://github.com/bytedeco/javacpp-presets/blob/master/opencv/src/main/java/org/bytedeco/javacpp/opencv_core.java This object extends Pointer defined here: https://github.com/bytedeco/javacpp/blob/master/src/main/java/org/bytedeco/javacpp/Pointer.java This seems to keep fields with references to the memory addresses somewhere in the object. I suppose if you clone it this object will still be pointing to the same object so this won't work.

kostaskougios commented 9 years ago

They seem to use longs to point to the mem address as you say. So cloner will just copy the long number and point to the same address. But you can impl IFastCloner for Pointer.class and register that with cloner and provide your own cloning impl for it - if you have a way to copy the memory those longs point to.