JNIã§Cå´ã®ãã¤ã³ã¿ãä¿æããæ¹æ³ã«ã¤ãã¦
Cã®ãã¤ã³ã¿ãä¿æããã
ç¾å¨embulk-output-oracleãé«éåããããã«ãJNI(Java Native Interface)ã使ã£ã¦ããã°ã©ãã³ã°ãã¦ããã
Â
ãã®æã¡ãã£ã¨æ©ãã ã®ããCã®ãã¤ã³ã¿ãã©ããã£ã¦ä¿æããããã ã
ããã¼ã¨ãã¦ã¯ã
Java | Â | C |
---|---|---|
åæåå¦ç | â | å¿ è¦ãªã¡ã¢ãªãç¢ºä¿ |
å¦çæ¬ä½ | â | ã¡ã¢ãªã使ã£ã¦ããããå¦ç |
å¾å¦ç | â | ã¡ã¢ãªãè§£æ¾ |
ã®ãããªæãã ã
åæåæã«ç¢ºä¿ããã¡ã¢ãªã®ãã¤ã³ã¿ããå¾ç¶ã®å¦çã«å¼ãç¶ãå¿ è¦ãããã
Â
ã©ããã£ã¦ãã¤ã³ã¿ãä¿æããã
ã¾ããCå´ã§ã°ãã¼ãã«å¤æ°ã§æã¤æ¹æ³ã
ããã ã¨ä¸¦åå¦çã«å¯¾å¿ã§ããªãããã ãã ã
Â
Javaå´ã«ãã¤ã³ã¿ãè¿ããå¾ç¶ã®å¦çã§æ¸¡ãç´ãã¦ãããæ¹æ³ãããã ããã
ã¨æã£ãããJavaã«ã¯ãã¤ã³ã¿åã¨ããã®ãç¡ããintã¨ãlongã«ãã£ã¹ãããã°ããã®ããªï¼ã¨ãæã£ãããå¦çç³»ä¾åã«ãªããæ°æã¡æªããªãã
Â
ã¡ãã£ã¨é¢åã«ãªãããJavaå´ã«ã¯intã®IDãè¿ããCå´ã§IDã¨ãã¤ã³ã¿ã¨ã®ãããã管çããæ¹æ³ãèããããã
STL(Standard Template Library)ã使ãã°ãmapãç°¡åã
ã¨æã£ããâ¦ãã©ããã¹ã¬ããã»ã¼ãã§ã¯ãªãã£ã½ããå¥ã®ã©ã¤ãã©ãªã§æä»å¶å¾¡ãè¡ããªãã¨ãããªãããã ã
Cã§æä»å¶å¾¡ããããªãã©ã¤ãã©ãªã¯â¦ï¼ãã¼ããããã©ããããªã£ã¦ããã
Â
ãã¤ãé åã§ä¿æããã°ããããããªãã ããã
çµå±ãå¦çç³»ã«ãã£ã¦ãã¤ã³ã¿ã®ãµã¤ãºã¯éããããããªããããã¤ãé åã§æã£ã¡ããã°ããããããªãããªï¼ã¨èããã®ã ã
Â
ãã¤ã³ã¿ãããã¤ãé åã®å¤æã¯ãããªæãã
JNIEXPORT jbyteArray JNICALL initialize(JNIEnv *env, jobject) { void *buffer = ... jbyteArray pointer = env->NewByteArray(sizeof(void*)); env->SetByteArrayRegion(pointer, 0, sizeof(void*), (jbyte*)&buffer); return pointer; }
Â
Javaå´ã§ã¯ byte[] pointer ã®ããã«æã¤ãã¨ãã§ããã
Â
ãã¤ãé åããã¤ã³ã¿ã«æ»ãã®ã¯ãããªæãã
JNIEXPORT void JNICALL release(JNIEnv *env, jobject, jbyteArray pointer) { void *buffer; env->GetByteArrayRegion(pointer, 0, sizeof(buffer), (jbyte*)&buffer); ... }
Â
ä¸æéæãããã©ããããªãå¦çç³»ã«ãããJavaå´ã®ã³ã¼ãã¯çµ±ä¸ã§ãããã¯ãããã¶ãã
Â