Class PointerScope

java.lang.Object
org.bytedeco.javacpp.PointerScope
All Implemented Interfaces:
AutoCloseable

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 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 Details

    • PointerScope

      public PointerScope()
      Creates a new scope accepting all pointer types and pushes itself on the scopeStack.
    • PointerScope

      public PointerScope(Class<? extends Pointer>... forClasses)
      Initializes forClasses, and pushes itself on the scopeStack.
  • Method Details

    • getInnerScope

      public static PointerScope getInnerScope()
      Returns scopeStack.get().peek(), the last opened scope not yet closed.
    • getScopeIterator

      public static Iterator<PointerScope> getScopeIterator()
      Returns scopeStack.get().iterator(), all scopes not yet closed.
    • forClasses

      public Class<? extends Pointer>[] forClasses()
    • attach

      public PointerScope attach(Pointer p)
      Pushes the Pointer onto the pointerStack of this Scope and calls Pointer.retainReference().
      Throws:
      IllegalArgumentException - when it is not an instance of a class in forClasses.
    • detach

      public PointerScope detach(Pointer p)
      Removes the Pointer from the pointerStack of this Scope and calls Pointer.releaseReference().
    • extend

      public PointerScope extend()
      Extends the life of this scope past the next call to close() by setting the extend flag.
    • close

      public void close()
      Pops from pointerStack all attached pointers, calls Pointer.releaseReference() on them, unless extended, in which case it only resets the extend flag instead, and finally removes itself from scopeStack.
      Specified by:
      close in interface AutoCloseable
    • deallocate

      public void deallocate()
      Pops from pointerStack all attached pointers, and calls Pointer.deallocate() on them.