Class PointerScope
java.lang.Object
org.bytedeco.javacpp.PointerScope
- All Implemented Interfaces:
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.-
Field Summary
FieldsModifier and TypeFieldDescription(package private) booleanWhen set to true, the next call toclose()does not release but resets this variable.When not empty, indicates the classes of objects that are allowed to be attached.private static final LoggerThe stack keeping references to attachedPointerobjects.(package private) static final ThreadLocal<Deque<PointerScope>> A thread-local stack ofPointerScopeobjects. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new scope accepting all pointer types and pushes itself on thescopeStack.PointerScope(Class<? extends Pointer>... forClasses) InitializesforClasses, and pushes itself on thescopeStack. -
Method Summary
Modifier and TypeMethodDescriptionPushes 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.voidPops frompointerStackall attached pointers, and callsPointer.deallocate()on them.Removes the Pointer from thepointerStackof this Scope and callsPointer.releaseReference().extend()static PointerScopeReturnsscopeStack.get().peek(), the last opened scope not yet closed.static Iterator<PointerScope> ReturnsscopeStack.get().iterator(), all scopes not yet closed.
-
Field Details
-
logger
-
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
-
forClasses
-
extend
boolean extendWhen set to true, the next call toclose()does not release but resets this variable.
-
-
Constructor Details
-
PointerScope
public PointerScope()Creates a new scope accepting all pointer types and pushes itself on thescopeStack. -
PointerScope
InitializesforClasses, and pushes itself on thescopeStack.
-
-
Method Details
-
getInnerScope
ReturnsscopeStack.get().peek(), the last opened scope not yet closed. -
getScopeIterator
ReturnsscopeStack.get().iterator(), all scopes not yet closed. -
forClasses
-
attach
Pushes the Pointer onto thepointerStackof this Scope and callsPointer.retainReference().- Throws:
IllegalArgumentException- when it is not an instance of a class inforClasses.
-
detach
Removes the Pointer from thepointerStackof this Scope and callsPointer.releaseReference(). -
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 interfaceAutoCloseable
-
deallocate
public void deallocate()Pops frompointerStackall attached pointers, and callsPointer.deallocate()on them.
-