Compact Off-Heap Structures and Tuples In Java
mechanical-sympathy.blogspot.co.uk
mechanical-sympathy.blogspot.co.uk
For those interested, there are less low-level ways to access fields in structures, for example Javolution http://javolution.org/target/site/apidocs/javolution/io/Stru...
I'm working on a very similar lib but where Structs are stateless, allowing to use them concurrently from multiple threads.
Basically, there are 3 notions
1) the buffer (byte[] or whatever) containing the data, immutable at least while the data is being accessed by a given thread
2) the Struct object: defines the structure of a message (field length, offset, arrays etc.)
3) the Message (aka the flyweight) that points to a given offset in buffer and is bound to a Struct instance
The buffer and the message are normally accessed by only one thread, but several threads can share Struct instances (i.e. the dictionary).
Each field (even deep in the field hierarchy) knows its offset relative to the beginning of the message, so values can be accessed like eg.
int foo = struct.foo.getInt(msg);
The only complicated thing is when dealing with arrays (especially when nested in other arrays). The message does the bookkeeping necessary to safely access elements, ie. the mutable state is stored in the flyweight.For a non-hadoop datasource you could do the same thing by hand: stream in the data from the table, turning it into objects from your pool and passing them through to your reducer function in small batches.