| This class holds factories to produces arrays of variable length.
It allows for object recycling, pre-allocation and
StackContextstack allocations:[code]
// Primitive types.
char[] buffer = ArrayFactory.CHARS_FACTORY.array(1024); // Possibly recycled.
for (int i = reader.read(buffer, 0, buffer.length); i > 0;) {
...
}
ArrayFactory.CHARS_FACTORY.recycle(buffer); //
// Custom types.
static ArrayFactory VERTICES_FACTORY = new ArrayFactory {
protected Vertex[] create(int size) {
return new Vertex[size];
}
};
...
Vertex[] vertices = VERTICES_FACTORY.array(256);
[/code]
author: Jean-Marie Dautelle version: 5.0, May 5, 2007 |