gzz.util
Class BlockPool

java.lang.Object
  |
  +--gzz.util.BlockPool

public abstract class BlockPool
extends java.lang.Object

A pool for blocks of throw-away objects. A different implementation of pooling, for experimentation. This class makes the pool logic simpler by not making it possible to release a single object at a time.

Therefore, we get rid of the boolean array used and the storage of an integer index per poolable object.

The use of this class requires some more care from the higher-level programmer.


Field Summary
static int INITIAL_LENGTH
          The initial size of the pool array.
protected  int nPooled
          The number of used entries.
protected  java.lang.Object[] pool
          The pool of Poolables.
static java.lang.String rcsid
           
 
Constructor Summary
BlockPool()
           
 
Method Summary
protected abstract  java.lang.Object create()
          Create a new object of the type cached by this Pool.
 java.lang.Object getObject()
          Get a Placeable object not yet casted to the class this Pool caches.
 int getSize()
          Get the current pool size.
 void setSize(int size)
          Set the current pool size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rcsid

public static final java.lang.String rcsid
See Also:
Constant Field Values

INITIAL_LENGTH

public static final int INITIAL_LENGTH
The initial size of the pool array. Note: no new objects are created until specifically requested. Initially, all the pointers in the pool array are to null.

See Also:
Constant Field Values

pool

protected java.lang.Object[] pool
The pool of Poolables. Valid at least up to n-1. When looking beyond endIndex-1, one must test for null entries and possibly create new objects through create().


nPooled

protected int nPooled
The number of used entries.

Constructor Detail

BlockPool

public BlockPool()
Method Detail

create

protected abstract java.lang.Object create()
Create a new object of the type cached by this Pool. This method is called by the getObject() method when there is no cached, currently unused instance. It does not have to worry about putting the object into the cache array or about calling setPool in the Poolable: the getObject() method will take care of that.


getObject

public final java.lang.Object getObject()
Get a Placeable object not yet casted to the class this Pool caches. If there is an unused object instance available, it is returned (and claimed as used); otherwise, a new instance is created and put into the cache.


getSize

public int getSize()
Get the current pool size.


setSize

public void setSize(int size)
Set the current pool size. The entries created after getSize() returned size are considered discarded.