javolution.context
Class StackContext
java.lang.Object
javolution.context.Context
javolution.context.AllocatorContext
javolution.context.StackContext
- All Implemented Interfaces:
- java.io.Serializable, XMLSerializable
public abstract class StackContext
- extends AllocatorContext
This class represents a stack allocator context
;
(using thread-local pools or RTSJ ScopedMemory
).
Stacks allocations reduce heap memory allocation and often result in
faster execution time for almost all objects but the smallest one.
Stack allocated objects should never be assigned to static members
(see ImmortalContext
). Also, methods entering/exiting stack
contexts should ensure that stack allocated objects do not escape from
their context scope. If necessary, stack objects can be exported using
AllocatorContext.outerExecute(java.lang.Runnable)
or AllocatorContext.outerCopy(T)
:
public class LargeInteger implements ValueType, Realtime {
public LargeInteger sqrt() {
StackContext.enter();
try {
LargeInteger result = ZERO;
LargeInteger k = this.shiftRight(this.bitLength() / 2)); // First approximation.
while (true) { // Newton Iteration.
result = (k.plus(this.divide(k))).shiftRight(1);
if (result.equals(k)) return StackContext.outerCopy(result); // Exports result.
k = result;
}
} finally {
StackContext.exit();
}
}
}
- Version:
- 5.2, August 19, 2007
- Author:
- Jean-Marie Dautelle
- See Also:
- Serialized Form
Fields inherited from class javolution.context.Context |
ROOT |
Method Summary |
static void |
enter()
Enters the DEFAULT stack context. |
static void |
exit()
Exits the current stack context. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
DEFAULT
public static final Configurable<java.lang.Class<? extends StackContext>> DEFAULT
- Holds the default implementation. This implementation uses thread-local
pools. RTSJ alternative implementations could use
ScopedMemory
for their stack allocations.
Users may also disable stack allocation by providing a class allocating
on the heap.
StackContext
public StackContext()
enter
public static void enter()
- Enters the
DEFAULT
stack context.
exit
public static void exit()
- Exits the current stack context.
- Throws:
java.lang.ClassCastException
- if the context is not a stack context.
Copyright © 2005 - 2009 Javolution.