mirror of
https://github.com/google/flatbuffers.git
synced 2026-07-01 23:13:57 +00:00
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:
committed by
Wouter van Oortmerssen
parent
7bebaab69e
commit
9c169083ad
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user