This interface identifies objects which can be manipulated by
value; a JVM implementation may allocate instances of this class
on the stack and pass references by copy.
Realtime instances can be "explicitly" allocated on the
"stack" by executing within a
javolution.context.StackContext StackContext and creating new instances with an
javolution.context.ObjectFactory ObjectFactory .
It is the responsibility of the users to ensure
that "stack" objects are
javolution.context.StackContext.outerCopycopied out when
referenced outside of the stack context. For example:[code]
public final class Complex implements Realtime, ValueType { ... }
...
public Complex sumOf(Complex[] values) {
StackContext.enter(); // Starts stack allocation.
try {
Complex sum = Complex.ZERO;
for (Complex c : values) {
sum = sum.plus(c);
}
return StackContext.outerCopy(sum); // Copies outside the stack.
} finally {
StackContext.exit(); // Resets stacks.
}
}[/code]
Note: "Stack" allocation is not the only optimization that a VM
can do on
ValueType . The VM might decide not to perform any
allocation at all and store values directly in registers.
author: Jean-Marie Dautelle version: 5.0, May 6, 2007 |