com.caucho.util
Class FreeList<T>

java.lang.Object
  extended by com.caucho.util.FreeList<T>

public final class FreeList<T>
extends java.lang.Object

FreeList provides a simple class to manage free objects. This is useful for large data structures that otherwise would gobble up huge GC time.

The free list is bounded. Freeing an object when the list is full will do nothing.


Constructor Summary
FreeList(int size)
          Create a new free list.
 
Method Summary
 T allocate()
          Try to get an object from the free list.
 boolean checkDuplicate(T obj)
          Debugging to see if the object has already been freed.
 boolean free(T obj)
          Frees the object.
 boolean freeCareful(T obj)
          Frees the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FreeList

public FreeList(int size)
Create a new free list.

Parameters:
initialSize - maximum number of free objects to store.
Method Detail

allocate

public T allocate()
Try to get an object from the free list. Returns null if the free list is empty.

Returns:
the new object or null.

free

public boolean free(T obj)
Frees the object. If the free list is full, the object will be garbage collected.

Parameters:
obj - the object to be freed.

freeCareful

public boolean freeCareful(T obj)
Frees the object. If the free list is full, the object will be garbage collected.

Parameters:
obj - the object to be freed.

checkDuplicate

public boolean checkDuplicate(T obj)
Debugging to see if the object has already been freed.