Skip to content

Instantly share code, notes, and snippets.

@OpenGamma-Blog
Created May 24, 2012 13:40
Show Gist options
  • Save OpenGamma-Blog/2781598 to your computer and use it in GitHub Desktop.
Save OpenGamma-Blog/2781598 to your computer and use it in GitHub Desktop.
JNI Example 1 - OpenGamma
/*
* Class: NativeInterfaceTest
* Method: dgemv_critical_
* Signature: ([C[I[I[D[D[I[D[I[D[D[I)V
*/
JNIEXPORT void JNICALL Java_NativeInterfaceTestLAPACK_dgemv_1critical_1 (j<type> foo, ...)
{
j<type> foo;
#define MACRO_criticalGetPointer(var)\
c##var = (*env)->GetPrimitiveArrayCritical(env,var,NULL);
// grab memory, repeat for each argv[], would normally check return etc
MACRO_criticalGetPointer(foo)
assert(foo!=NULL); // in case memcpy() was attempted and failed from OOM.
// make the call, would normally wrap in a safe F77_FUNC style macro to catch Fortran STOPs etc but for example purposes a direct call will do
dgemv_(foo,...);
#define MACRO_criticalFreePointer(var)\
(*env)->ReleasePrimitiveArrayCritical(env, var, c##var, 0);
// release memory, repeat for each argv[], would normally check return etc
MACRO_criticalFreePointer(foo)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment