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.AutoCloseable
Pointer
objects attach themselves automatically onPointer.init(long, long, long, long)
to the firstPointerScope
found inscopeStack
that 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) boolean
extend
When set to true, the next call toclose()
does not release but resets this variable.(package private) java.lang.Class<? extends Pointer>[]
forClasses
When not empty, indicates the classes of objects that are allowed to be attached.private static Logger
logger
(package private) java.util.Deque<Pointer>
pointerStack
The stack keeping references to attachedPointer
objects.(package private) static java.lang.ThreadLocal<java.util.Deque<PointerScope>>
scopeStack
A thread-local stack ofPointerScope
objects.
-
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 PointerScope
attach(Pointer p)
Pushes the Pointer onto thepointerStack
of this Scope and callsPointer.retainReference()
.void
close()
Pops frompointerStack
all attached pointers, callsPointer.releaseReference()
on them, unless extended, in which case it only resets theextend
flag instead, and finally removes itself fromscopeStack
.void
deallocate()
Pops frompointerStack
all attached pointers, and callsPointer.deallocate()
on them.PointerScope
detach(Pointer p)
Removes the Pointer from thepointerStack
of this Scope and callsPointer.releaseReference()
.PointerScope
extend()
java.lang.Class<? extends Pointer>[]
forClasses()
static PointerScope
getInnerScope()
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 ofPointerScope
objects. 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 attachedPointer
objects.
-
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 thepointerStack
of 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 thepointerStack
of this Scope and callsPointer.releaseReference()
.
-
extend
public PointerScope extend()
-
close
public void close()
Pops frompointerStack
all attached pointers, callsPointer.releaseReference()
on them, unless extended, in which case it only resets theextend
flag instead, and finally removes itself fromscopeStack
.- Specified by:
close
in interfacejava.lang.AutoCloseable
-
deallocate
public void deallocate()
Pops frompointerStack
all attached pointers, and callsPointer.deallocate()
on them.
-
-