Commit 9c169083 authored by Florian Enner's avatar Florian Enner Committed by Wouter van Oortmerssen

Added FlatBufferBuilder reuse

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

Change-Id: If2aa7d27de3c2717cf4c82b1e4e4b6732e495cea
parent 7bebaab6
...@@ -59,10 +59,29 @@ public class FlatBufferBuilder { ...@@ -59,10 +59,29 @@ public class FlatBufferBuilder {
* @param existing_bb The byte buffer to reuse * @param existing_bb The byte buffer to reuse
*/ */
public FlatBufferBuilder(ByteBuffer existing_bb) { 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 = existing_bb;
bb.clear(); bb.clear();
bb.order(ByteOrder.LITTLE_ENDIAN); bb.order(ByteOrder.LITTLE_ENDIAN);
minalign = 1;
space = bb.capacity(); 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) { static ByteBuffer newByteBuffer(int capacity) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment