Package com.avpkit.ferry
Class JNIMemoryAllocator
- java.lang.Object
-
- com.avpkit.ferry.JNIMemoryAllocator
-
public final class JNIMemoryAllocator extends java.lang.Object
Internal Only.This object allocates large memory chunks and returns them to native code. The native memory then pins raw bytes based on the byte[]s returned here. The net effect is that Java ends up thinking it actually allocated the memory, but since a
RefCountedobject will also maintain a reference to this allocator, you can use this to detect instances of 'leaked' references in your Java code.This function is called DIRECTLY from native code; names of methods MUST NOT CHANGE.
- Author:
- aclarke
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidfree(byte[] mem)Free memory allocated by themalloc(int)method.static JNIMemoryAllocatorgetAllocator(long nativeObj)Internal Only.byte[]malloc(int size)Internal Only.static voidsetAllocator(long nativeObj, JNIMemoryAllocator mgr)Internal Only.
-
-
-
Method Detail
-
malloc
public byte[] malloc(int size)
Internal Only. Allocate a new block of bytes. Called from native code.Will retry many times if it can't get memory, backing off in timeouts to get there.
Callers must eventually call
free(byte[])when done with the bytes or a leak will result.- Parameters:
size- # of bytes requested- Returns:
- An array of size or more bytes long, or null on failure.
-
free
public void free(byte[] mem)
Free memory allocated by themalloc(int)method. Called from native code.- Parameters:
mem- the byes to be freed.
-
setAllocator
public static void setAllocator(long nativeObj, JNIMemoryAllocator mgr)
Internal Only. Native method that tells a native objects (represented by the nativeObj long pointer val) that this JNIMemoryAllocator is being used to allocate it's large blocks of memory.Follow that? No. That's OK... you really don't want to know.
- Parameters:
nativeObj- A C pointer (a la swig).mgr- Us.
-
getAllocator
public static JNIMemoryAllocator getAllocator(long nativeObj)
Internal Only. Get the allocator for the underlying native pointer.- Parameters:
nativeObj- The native pointer.- Returns:
- The allocator to use, or null.
-
-