Package org.bytedeco.javacpp
Class PointerScope
- java.lang.Object
-
- org.bytedeco.javacpp.PointerScope
-
- All Implemented Interfaces:
java.lang.AutoCloseable
public class PointerScope extends java.lang.Object implements java.lang.AutoCloseablePointerobjects attach themselves automatically onPointer.init(long, long, long, long)to the firstPointerScopefound inscopeStackthat they can to based on the classes found inforClasses. The user can then calldeallocate(), or rely onclose()to release in a timely fashion all attached Pointer objects, instead of relying on the garbage collector.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) booleanextendWhen set to true, the next call toclose()does not release but resets this variable.(package private) java.lang.Class<? extends Pointer>[]forClassesWhen not empty, indicates the classes of objects that are allowed to be attached.private static Loggerlogger(package private) java.util.Deque<Pointer>pointerStackThe stack keeping references to attachedPointerobjects.(package private) static java.lang.ThreadLocal<java.util.Deque<PointerScope>>scopeStackA thread-local stack ofPointerScopeobjects.
-
Constructor Summary
Constructors Constructor Description PointerScope()Creates a new scope accepting all pointer types and pushes itself on thescopeStack.PointerScope(java.lang.Class<? extends Pointer>... forClasses)InitializesforClasses, and pushes itself on thescopeStack.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PointerScopeattach(Pointer p)Pushes the Pointer onto thepointerStackof this Scope and callsPointer.retainReference().voidclose()Pops frompointerStackall attached pointers, callsPointer.releaseReference()on them, unless extended, in which case it only resets theextendflag instead, and finally removes itself fromscopeStack.voiddeallocate()Pops frompointerStackall attached pointers, and callsPointer.deallocate()on them.PointerScopedetach(Pointer p)Removes the Pointer from thepointerStackof this Scope and callsPointer.releaseReference().PointerScopeextend()java.lang.Class<? extends Pointer>[]forClasses()static PointerScopegetInnerScope()ReturnsscopeStack.get().peek(), the last opened scope not yet closed.static java.util.Iterator<PointerScope>getScopeIterator()ReturnsscopeStack.get().iterator(), all scopes not yet closed.
-
-
-
Field Detail
-
logger
private static final Logger logger
-
scopeStack
static final java.lang.ThreadLocal<java.util.Deque<PointerScope>> scopeStack
A thread-local stack ofPointerScopeobjects. Pointer objects attach themselves automatically onPointer.init(long, long, long, long)to the first one they can to on the stack.
-
pointerStack
java.util.Deque<Pointer> pointerStack
The stack keeping references to attachedPointerobjects.
-
forClasses
java.lang.Class<? extends Pointer>[] forClasses
When not empty, indicates the classes of objects that are allowed to be attached.
-
extend
boolean extend
When set to true, the next call toclose()does not release but resets this variable.
-
-
Constructor Detail
-
PointerScope
public PointerScope()
Creates a new scope accepting all pointer types and pushes itself on thescopeStack.
-
PointerScope
public PointerScope(java.lang.Class<? extends Pointer>... forClasses)
InitializesforClasses, and pushes itself on thescopeStack.
-
-
Method Detail
-
getInnerScope
public static PointerScope getInnerScope()
ReturnsscopeStack.get().peek(), the last opened scope not yet closed.
-
getScopeIterator
public static java.util.Iterator<PointerScope> getScopeIterator()
ReturnsscopeStack.get().iterator(), all scopes not yet closed.
-
forClasses
public java.lang.Class<? extends Pointer>[] forClasses()
-
attach
public PointerScope attach(Pointer p)
Pushes the Pointer onto thepointerStackof this Scope and callsPointer.retainReference().- Throws:
java.lang.IllegalArgumentException- when it is not an instance of a class inforClasses.
-
detach
public PointerScope detach(Pointer p)
Removes the Pointer from thepointerStackof this Scope and callsPointer.releaseReference().
-
extend
public PointerScope extend()
-
close
public void close()
Pops frompointerStackall attached pointers, callsPointer.releaseReference()on them, unless extended, in which case it only resets theextendflag instead, and finally removes itself fromscopeStack.- Specified by:
closein interfacejava.lang.AutoCloseable
-
deallocate
public void deallocate()
Pops frompointerStackall attached pointers, and callsPointer.deallocate()on them.
-
-