JNI - Caching IDs

来源:互联网 发布:手机卡 非实名 淘宝 编辑:程序博客网 时间:2024/05/29 13:27

Method 1. Caching at the Point of Use

static jmethodID cid = NULL;if (cid == NULL){cid = (*env)->GetMethodID(env,stringClass,"<init>","([C)V");if (cid == NULL){return NULL;}}


Method 2. Caching in the Defining class's Initializer

in java,

class InstanceOfMethodCall{private static native void initIDs();Static{System.loadLibrary("InstanceOfMethodCall");initIDs();}}


in C,

in .c file,jmethodID mid;initIDs(JNIEnv *env, jclass cls){mid = (*env)->GetMethodID(env, cls, "METHOD_NAME","()V");}


0 0