The native addresses generated by this class do not relate to the object's true native address (since that is not supported by most java virtual machines), but is guaranteed to be unique within an ObjectReferenceManager instance.
This would be commonly used to create a unique native pointer that can be used to retrieve an object from within a callback. e.g.
public interface MyLib {
public static interface MyCallback {
@Delegate public void call(Pointer value);
}
public void do_something_with_callback(MyCallback cb, Pointer cb_argument);
}
MyLib lib = LibraryLoader.create(MyLib.class).load("mylib");
final ObjectReferenceManager referenceManager = Runtime.getRuntime(lib).newObjectReferenceManager();
MyCallback cb = new MyCallback {
public void call(Pointer cb_argument) {
Object javaCallbackArgument = referenceManager.get(cb_argument);
System.out.println("java callback parameter=" + javaCallbackArgument);
}
}
String callbackArgument = "Hello, World";
Pointer cb_argument = referenceManager.add(callback);
lib.do_something_with_callback(cb, cb_argument);
referenceManager.remove(cb_argument);
Note
Each call to add(Object) will return a unique native address, even for the same object, so each call to
add(Object) must be matched with a call to remove(Pointer).
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public abstract Pointer | Returns: A pointer representing the unique id.The java object to generate a reference for object)Adds a mapping from a java object to a unique native address. |
| public void | freeReference(Pointer
a native memory pointer. reference)
Deprecated
use
Removes a mapping from java object to native pointer.
remove(Pointer)
|
| public abstract T | |
| public T | Returns: The java object corresponding topointer.a native memory pointer. reference)
Deprecated
use
Gets the java object that is mapped to the native memory address referred to by get(Pointer)
reference.
|
| public static <T> ObjectReferenceManager | |
| public Pointer | Returns: A pointer representing the unique id.The java object to generate a reference for object)
Deprecated
use
Adds a mapping from a java object to a unique native address.
add(Object)
|
| public abstract boolean |
| ObjectReferenceManager | back to summary |
|---|---|
| public ObjectReferenceManager() | |
| add | back to summary |
|---|---|
| public abstract Pointer add(T object) Adds a mapping from a java object to a unique native address. Each call to this method is guaranteed to produce a memory address unique within the ObjectReferenceManager instance, even for the same object.
A strong reference to
| |
| freeReference | back to summary |
|---|---|
| public void freeReference(Pointer reference)
Deprecated use Removes a mapping from java object to native pointer.
| |
| get | back to summary |
|---|---|
| public abstract T get(Pointer reference) Gets the java object that is mapped to the native memory address referred to by
| |
| getObject | back to summary |
|---|---|
| public T getObject(Pointer reference)
Deprecated use Gets the java object that is mapped to the native memory address referred to by
| |
| newInstance | back to summary |
|---|---|
| public static <T> ObjectReferenceManager | |
| newReference | back to summary |
|---|---|
| public Pointer newReference(T object)
Deprecated use Adds a mapping from a java object to a unique native address. Each call to this method is guaranteed to produce a memory address unique within the ObjectReferenceManager instance, even for the same object.
A strong reference to
| |
| remove | back to summary |
|---|---|
| public abstract boolean remove(Pointer reference) Removes a mapping from java object to native pointer.
| |