public class PointerScope
extends java.lang.Object
implements java.lang.AutoCloseable
Pointer objects attach themselves automatically on Pointer.init(long, long, long, long) to the first PointerScope
found in scopeStack that they can to based on the classes found in forClasses. The user can then
call deallocate(), or rely on close() to release in a timely fashion all attached Pointer objects,
instead of relying on the garbage collector.| Constructor and Description |
|---|
PointerScope(java.lang.Class<? extends Pointer>... forClasses)
Initializes
forClasses, and pushes itself on the scopeStack. |
| Modifier and Type | Method and Description |
|---|---|
PointerScope |
attach(Pointer p)
Pushes the Pointer onto the
pointerStack of this Scope and calls Pointer.retainReference(). |
void |
close()
Pops from
pointerStack all attached pointers,
calls Pointer.releaseReference() on them, unless extended,
in which case it only resets the extend flag instead,
and finally removes itself from scopeStack. |
void |
deallocate()
Pops from
pointerStack all attached pointers,
and calls Pointer.deallocate() on them. |
PointerScope |
detach(Pointer p)
Removes the Pointer from the
pointerStack of this Scope
and calls Pointer.releaseReference(). |
PointerScope |
extend()
|
java.lang.Class<? extends Pointer>[] |
forClasses() |
static PointerScope |
getInnerScope()
Returns
scopeStack.get().peek(), the last opened scope not yet closed. |
static java.util.Iterator<PointerScope> |
getScopeIterator()
Returns
scopeStack.get().iterator(), all scopes not yet closed. |
public PointerScope(java.lang.Class<? extends Pointer>... forClasses)
forClasses, and pushes itself on the scopeStack.public static PointerScope getInnerScope()
scopeStack.get().peek(), the last opened scope not yet closed.public static java.util.Iterator<PointerScope> getScopeIterator()
scopeStack.get().iterator(), all scopes not yet closed.public java.lang.Class<? extends Pointer>[] forClasses()
public PointerScope attach(Pointer p)
pointerStack of this Scope and calls Pointer.retainReference().java.lang.IllegalArgumentException - when it is not an instance of a class in forClasses.public PointerScope detach(Pointer p)
pointerStack of this Scope
and calls Pointer.releaseReference().public PointerScope extend()
public void close()
pointerStack all attached pointers,
calls Pointer.releaseReference() on them, unless extended,
in which case it only resets the extend flag instead,
and finally removes itself from scopeStack.close in interface java.lang.AutoCloseablepublic void deallocate()
pointerStack all attached pointers,
and calls Pointer.deallocate() on them.