public interface PinnedObject extends AutoCloseable
This class implements AutoCloseable
so that the pinning can be managed conveniently with
a try-with-resource block that releases the pinning automatically:
int[] array = ... try (PinnedObject pin = PinnedObject.create(array)) { CIntPointer rawData = pin.addressOfArrayElement(0); // it is safe to pass rawData to a C function. } // it is no longer safe to access rawData.
Modifier and Type | Method and Description |
---|---|
<T extends PointerBase> |
addressOfArrayElement(int index)
Returns a pointer to the array element with the specified index.
|
PointerBase |
addressOfObject()
Returns the raw address of the pinned object.
|
void |
close()
Releases the pin for the object.
|
static PinnedObject |
create(Object object)
Create an open PinnedObject.
|
Object |
getObject()
Returns the Object that is the referent of this PinnedObject.
|
static PinnedObject create(Object object)
void close()
close
in interface AutoCloseable
Object getObject()
PointerBase addressOfObject()
<T extends PointerBase> T addressOfArrayElement(int index)