public class PointerScope extends Object implements AutoCloseable
Pointer objects attach themselves automatically on Pointer.init(long, long, long, long) to the first PointerScope
found in scopeStack. The user can then call deallocate(), or rely on close(),
to deallocate in a timely fashion all attached Pointer objects, instead of relying on the garbage collector.| Modifier and Type | Field and Description |
|---|---|
(package private) boolean |
deallocateOnClose
When true,
deallocate() gets called on close(). |
private static Logger |
logger |
(package private) Deque<Pointer> |
pointerStack
The stack keeping references to attached
Pointer objects. |
(package private) static ThreadLocal<Deque<PointerScope>> |
scopeStack
A thread-local stack of
PointerScope objects. |
| Constructor and Description |
|---|
PointerScope()
Calls
this(true). |
PointerScope(boolean deallocateOnClose)
Initializes
deallocateOnClose 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. |
void |
close()
|
void |
deallocate()
Calls
Pointer.deallocate() on all attached pointers,
as they are popped off the pointerStack. |
boolean |
deallocateOnClose()
Returns
deallocateOnClose. |
PointerScope |
deallocateOnClose(boolean deallocateOnClose)
Sets
deallocateOnClose and returns this Scope. |
PointerScope |
detach(Pointer p)
Removes the Pointer from the
pointerStack of this Scope. |
static PointerScope |
getInnerScope()
Returns
scopeStack.get().peek(), the last opened scope not yet closed. |
private static final Logger logger
static final ThreadLocal<Deque<PointerScope>> scopeStack
PointerScope objects. Pointer objects attach themselves
automatically on Pointer.init(long, long, long, long) to the first one on the stack.boolean deallocateOnClose
deallocate() gets called on close().public PointerScope()
this(true).public PointerScope(boolean deallocateOnClose)
deallocateOnClose and pushes itself on the scopeStack.public static PointerScope getInnerScope()
scopeStack.get().peek(), the last opened scope not yet closed.public PointerScope deallocateOnClose(boolean deallocateOnClose)
deallocateOnClose and returns this Scope.public boolean deallocateOnClose()
deallocateOnClose.public PointerScope attach(Pointer p)
pointerStack of this Scope.public PointerScope detach(Pointer p)
pointerStack of this Scope.public void close()
close in interface AutoCloseablepublic void deallocate()
Pointer.deallocate() on all attached pointers,
as they are popped off the pointerStack.Copyright © 2019. All rights reserved.