How to use JNI to call MEMCMP from Java -
i need compare 2 byte arrays , know 1 bigger or if equal (just equal or different not enough). byte arrays represent string value of 15 characters or more. comparison repeated considerably in code.
i improve bye array compare using equivalent of c++ memcmp method in java (hopefully jni). found example use dllimport in c#, hope jni call can applied well.
here c# code segment:
[dllimport("msvcrt.dll")] unsafe static extern int memcmp(void* b1, void* b2, long count); unsafe static int bytearraycompare1(byte[] b1, int b1index, int b1length, byte[] b2, int b2index, int b2length) { comparecount++; fixed (byte* p1 = b1) fixed (byte* p2 = b2) { int cmp = memcmp(p1 + b1index, p2 + b2index, math.min(b1length, b2length)); if (cmp == 0) { cmp = b1length.compareto(b2length); } return cmp; } }
does know how implement in java?
thanks in advance,
diana
are code spending significant time on comparisons? suggest calling java function now, , timing it; if still need to, can add jni/jna.
remember adding jni increase chance of bugs significantly, , limit program architectures compile library for.
Comments
Post a Comment