Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

For the purpose of passing a Rect by value (of its coordinates), I think the integer approach is the best.

This is because the other approaches for passing a Rect may incur more runtime cost, such as additional temporary object creation (if an integer or double array of size 4 is used) or JNI calls into Java object (if the Rect object is passed into JNI as-is).

For the Sun (now Oracle) Java 6 and up, temporary objects are not an overhead, thanks to Escape Analysis, implemented in Java compilers. However, there are certain "Java-like" mobile VM platforms which do not perform compilation or Ahead-of-Time analysis, so for these platforms the overhead exists.

If one has to pass a mutable Rect by reference (to be modified by OpenCV in JNI, and have the modification propagated back to the same Rect object passed in by the Java API caller), my suggestion is to use either a Rect or a MatOfRect. The runtime overhead will be inevitable in this case.

Reference:

click to hide/show revision 2
Added links to Java JNI reference.

For the purpose of passing a Rect by value (of its coordinates), I think the integer approach is the best.

This is because the other approaches for passing a Rect may incur more runtime cost, such as additional temporary object creation (if an integer or double array of size 4 is used) or JNI calls into Java object (if the Rect object is passed into JNI as-is).

For the Sun (now Oracle) Java 6 and up, temporary objects are not an overhead, thanks to Escape Analysis, implemented in Java compilers. However, there are certain "Java-like" mobile VM platforms which do not perform compilation or Ahead-of-Time analysis, so for these platforms the overhead exists.

If one has to pass a mutable Rect by reference (to be modified by OpenCV in JNI, and have the modification propagated back to the same Rect object passed in by the Java API caller), my suggestion is to use either a Rect or a MatOfRect. The runtime overhead will be inevitable in this case.

Reference: