Added FlatBufferBuilder reuse

init resets internal variables, but keeps memory that has been allocated
for temporary storage

Change-Id: If2aa7d27de3c2717cf4c82b1e4e4b6732e495cea
This commit is contained in:
Florian Enner
2015-01-28 23:32:41 -05:00
committed by Wouter van Oortmerssen
parent 7bebaab69e
commit 9c169083ad

View File

@@ -59,10 +59,29 @@ public class FlatBufferBuilder {
* @param existing_bb The byte buffer to reuse
*/
public FlatBufferBuilder(ByteBuffer existing_bb) {
init(existing_bb);
}
/**
* Alternative initializer that allows reusing this object on an existing
* ByteBuffer. This method resets the builder's internal state, but keeps
* objects that have been allocated for temporary storage.
*
* @param existing_bb The byte buffer to reuse
* @return this
*/
public FlatBufferBuilder init(ByteBuffer existing_bb){
bb = existing_bb;
bb.clear();
bb.order(ByteOrder.LITTLE_ENDIAN);
minalign = 1;
space = bb.capacity();
vtable_in_use = 0;
nested = false;
object_start = 0;
num_vtables = 0;
vector_num_elems = 0;
return this;
}
static ByteBuffer newByteBuffer(int capacity) {