jni fwrite memroy issue
861183May 11 2011 — edited May 11 2011I am trying to call the c function from java using jni. From java function I am passing 64 K as byte array. From the C program I am writing it to a file appending. The getNativeHeapFreeSize is getting decreased after each invokeSVM function call. And and the program throws Out of memory error. Could somebody tell me the reason for this?
java code
synchronized(res)
{
// byte[] copyBuf = new byte[640*480*2];//[args[0].length];
// System.arraycopy(args[0], 0, copyBuf, 0, 640*480*2);
int ret = invokeSVM(args[0], res);
//----
Log.d(TAG, "getNativeHeapSize = " + String.valueOf(Debug.getNativeHeapSize()));
Log.d(TAG, "getNativeHeapFreeSize = " + String.valueOf(Debug.getNativeHeapFreeSize()));
Log.d(TAG, "getNativeHeapAllocatedSize = " + String.valueOf(Debug.getNativeHeapAllocatedSize()));
//----
Log.d(TAG, "XXXXXXXXXXXXXXXXXXXXXX Value: " + String.valueOf(ret) + "xxxxxxxxxxx");
if(ret == 0)
{
Log.e(TAG, "HHHHHHHHH SVM Algorithm not success HHHHHHHH");
}
}
return res;
}
c code
function invokeSVM ()
{
...........
fp = fopen ("/sdcard/image_after.yuv","a+");
fwrite (outArray, 1, 640*480*3, fp);
fclose (fp);
.............
}