Open
Description
Currently, the Java Callable Wrappers use an ArrayList
and methods to help mirror the object graph from the Mono GC to the Android GC:
/* partial */ class Example {
ArrayList<Object> managedReferences = new ArrayList<Object>();
public void monodroidAddReference (Object o) {
managedReferences.add (o);
}
public void monodroidClearReferences () {
managedReferences.clear ();
}
}
monodroidAddReference()
and monodroidClearReferences()
are called via JNI within osbridge.cc
:
An idea occurred to me: what if instead of invoking monodroidAddReference()
/etc., we instead used a field?
/* partial */ class Example {
Object []managedReferences;
}
This would reduce Java-side memory allocations (no ArrayList<Object>
), and would alter the number of JNI invocations needed, from num_xrefs
JNIEnv::CallVoidMethod()
invocations to num_xrefs
calls to JNIEnv::SetObjectArrayElement()
+ 1 JNIEnv::SetObjectField()
. (Presumably JNIEnv::SetObjectArrayElement()
will be faster than JNIEnv::CallVoidMethod()
.)