Interface ThreadLocalPool<E>

Type Parameters:
E - Type of Buffer that will be created

public interface ThreadLocalPool<E>
A thread local pool used by a MemoryManager to create and modify Buffers
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    allocate(int size)
    Creates a buffer with a given capacity and limit
    boolean
    Whether there are elements between the current position and the end
    boolean
    isLastAllocated(E oldBuffer)
    Whether the last element in the buffer has been set
    reallocate(E oldBuffer, int newSize)
    Creates a new Buffer with a set size and assigns it the data that was held in the old one as long as the given size is not smaller than the data held.
    Reduces the buffer to the last data allocated
    boolean
    release(E underlyingBuffer)
    deallocates the data in the buffer
    int
    Gets the number of elements between the current position and the limit
    void
    reset(E pool)
    Resets the Buffer to empty values and empties the pool
    boolean
    wantReset(int size)
    Checks if the size of the Buffer should be reset.
  • Method Details

    • reset

      void reset(E pool)
      Resets the Buffer to empty values and empties the pool
      Parameters:
      pool - the buffer to reset
    • allocate

      E allocate(int size)
      Creates a buffer with a given capacity and limit
      Parameters:
      size - maximum number of elements
      Returns:
      the new buffer
      See Also:
    • reallocate

      E reallocate(E oldBuffer, int newSize)
      Creates a new Buffer with a set size and assigns it the data that was held in the old one as long as the given size is not smaller than the data held.
      Parameters:
      oldBuffer - Old Buffer containing data
      newSize - The size the new Buffer should be.
      Returns:
      the new Buffer or null if the buffer could not be resized
    • release

      boolean release(E underlyingBuffer)
      deallocates the data in the buffer
      Parameters:
      underlyingBuffer - the buffer to release
      Returns:
      true if operation successfully completed, false otherwise
    • isLastAllocated

      boolean isLastAllocated(E oldBuffer)
      Whether the last element in the buffer has been set
      Parameters:
      oldBuffer - the buffer to check
      Returns:
      true if the end of the buffer has been allocated, false otherwise
    • reduceLastAllocated

      E reduceLastAllocated(E buffer)
      Reduces the buffer to the last data allocated
      Parameters:
      buffer -
      Returns:
      the old buffer data that was removed. This may be null.
    • wantReset

      boolean wantReset(int size)
      Checks if the size of the Buffer should be reset.
      Parameters:
      size - the desired size of the buffer. If this is less than the current size ofthe buffer then this will return false
      Returns:
      true if the the buffer should be enlarged to hold the desired size
    • remaining

      int remaining()
      Gets the number of elements between the current position and the limit
      Returns:
      number of elements
    • hasRemaining

      boolean hasRemaining()
      Whether there are elements between the current position and the end
      Returns:
      true if there are unused elements, false otherwise