Class Allocator<T>


  • public class Allocator<T>
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) int blockSize  
      (package private) int index  
      java.util.Vector<T[]> memory  
      (package private) int remains  
    • Constructor Summary

      Constructors 
      Constructor Description
      Allocator()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void dispose()  
      AllocatorState getState()
      This method returns the memory state of the allocator.
      T[] newElements​(int elements)
      This method returns a pointer to an array of elements objects.
      (package private) void reset()
      This method is the allocators destructor.
      void rollBack()
      This method rolls back the allocator so that it makes all of the memory previously allocated available for re-allocation.
      void rollBack​(AllocatorState state)
      This method rolls back the allocator to the previous memory state and makes all of the memory previously allocated available for re-allocation.
      void set​(int blockSize)
      This method initiallizes the constructor and the blockSize variable specifies the the number of objects that should be pre-allocated at a time.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • blockSize

        int blockSize
      • index

        int index
      • remains

        int remains
      • memory

        public java.util.Vector<T[]> memory
    • Constructor Detail

      • Allocator

        public Allocator()
    • Method Detail

      • dispose

        public void dispose()
      • reset

        void reset()
        This method is the allocators destructor. It frees up any of the memory that it has allocated.
      • getState

        public AllocatorState getState()
        This method returns the memory state of the allocator.
      • rollBack

        public void rollBack()
        This method rolls back the allocator so that it makes all of the memory previously allocated available for re-allocation. Note that it does it not call the constructor again, so after this method has been called, assumptions about the state of the values in memory are no longer valid.
      • rollBack

        public void rollBack​(AllocatorState state)
        This method rolls back the allocator to the previous memory state and makes all of the memory previously allocated available for re-allocation. Note that it does it not call the constructor again, so after this method has been called, assumptions about the state of the values in memory are no longer valid.
      • set

        public void set​(int blockSize)
        This method initiallizes the constructor and the blockSize variable specifies the the number of objects that should be pre-allocated at a time.
      • newElements

        public T[] newElements​(int elements)
        This method returns a pointer to an array of elements objects. If there is left over pre-allocated memory, this method simply returns a pointer to the next free piece of memory, otherwise it pre-allocates more memory. Note that if the number of objects requested is larger than the value blockSize with which the allocator was initialized, the request for memory will fail.