
public final class JNIMemoryAllocator extends Object
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 RefCounted object 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.
| Modifier and Type | Method and Description |
|---|---|
void |
free(byte[] mem)
Free memory allocated by the
malloc(int) method. |
static JNIMemoryAllocator |
getAllocator(long nativeObj)
Internal Only.
|
byte[] |
malloc(int size)
Internal Only.
|
static void |
setAllocator(long nativeObj,
JNIMemoryAllocator mgr)
Internal Only.
|
public byte[] malloc(int size)
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.
size - # of bytes requestedpublic void free(byte[] mem)
malloc(int) method.
Called from native code.mem - the byes to be freed.public static void setAllocator(long nativeObj,
JNIMemoryAllocator mgr)
Follow that? No. That's OK... you really don't want to know.
nativeObj - A C pointer (a la swig).mgr - Us.public static JNIMemoryAllocator getAllocator(long nativeObj)
nativeObj - The native pointer.Copyright © 2018 Humble Software. All rights reserved.