com.bulletphysics.util
Class StackList<T>

java.lang.Object
  extended by com.bulletphysics.util.StackList<T>
Direct Known Subclasses:
ObjectStackList

public abstract class StackList<T>
extends Object

Stack-based object pool, see the example for usage. You must use the returning(T) method for returning stack-allocated instance.

Example code:

 StackList<Vector3f> vectors;
 ...
 
 vectors.push();
 try {
     Vector3f vec = vectors.get();
     ...
     return vectors.returning(vec);
 }
 finally {
     vectors.pop();
 }
 


Constructor Summary
StackList()
           
 
Method Summary
 T get()
          Returns instance from stack pool, or create one if not present.
 void pop()
          Pops the stack.
 void push()
          Pushes the stack.
 T returning(T obj)
          Copies given instance into one slot static instance and returns it.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StackList

public StackList()
Method Detail

push

public final void push()
Pushes the stack.


pop

public final void pop()
Pops the stack.


get

public T get()
Returns instance from stack pool, or create one if not present. The returned instance will be automatically reused when pop() is called.

Returns:
instance

returning

public final T returning(T obj)
Copies given instance into one slot static instance and returns it. It's essential that caller of method (that uses this method for returning instances) immediately copies it into own variable before any other usage.

Parameters:
obj - stack-allocated instance
Returns:
one slot instance for returning purposes