Package org.bytedeco.javacpp
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.-
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()Extends the life of this scope past the next call toclose()by setting theextendflag.static PointerScopeReturnsscopeStack.get().peek(), the last opened scope not yet closed.static Iterator<PointerScope> ReturnsscopeStack.get().iterator(), all scopes not yet closed.
-
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
Extends the life of this scope past the next call toclose()by setting theextendflag. -
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.
-