Class BufferUtils

java.lang.Object
zombie.core.utils.BufferUtils

public final class BufferUtils extends Object
  • Constructor Details

    • BufferUtils

      public BufferUtils()
  • Method Details

    • setTrackDirectMemoryEnabled

      public static void setTrackDirectMemoryEnabled(boolean enabled)
      Set it to true if you want to enable direct memory tracking for debugging purpose. Default is false. To print direct memory usage use BufferUtils.printCurrentDirectMemory(StringBuilder store);
      Parameters:
      enabled -
    • printCurrentDirectMemory

      public static void printCurrentDirectMemory(StringBuilder store)
    • createByteBuffer

      public static ByteBuffer createByteBuffer(int size)
    • destroyDirectBuffer

      public static void destroyDirectBuffer(Buffer toBeDestroyed)
      Direct buffers are garbage collected by using a phantom reference and a reference queue. Every once a while, the JVM checks the reference queue and cleans the direct buffers. However, as this doesn't happen immediately after discarding all references to a direct buffer, it's easy to OutOfMemoryError yourself using direct buffers. This function explicitly calls the Cleaner method of a direct buffer.
      Parameters:
      toBeDestroyed - The direct buffer that will be "cleaned". Utilizes reflection.