Can I reuse 'sub' builder instances generated from a flatbuffers::FlatBufferBuilder after calling builder.Clear()? What is the effect of builder.Clear() on sub-builders?
Having generated a flatbuffers schema such as the following:
table FB_mytable1{
myshort::ushort = 0;
}
table FB_table2{
nestedTable1::FB_mytable1;
nestedTable1::FB_mytable1;
}
root_type FB_table2;
If I reset the builder using builder.clear(), my instantiation of 'flatbuffers::FlatBufferBuilder', will this allow me to generate new serial data without calling a reset function or renewing any of the individual table serialisers, such as my instantiation of FB_mytable1Builder myFB_mytable1Builder(builder)? Or do I need to ensure that the individual builder objects have a scope that means they are not reused?
clear()resets aFlatBufferBuilderas if just constructed, and any of the table builder instances should not be reused across multiple buffers or even multiple tables.See, a
FlatBufferBuilderis a somewhat heavyweight structure (since it owns a buffer), so it makes sense to reuse it when you can. The table builders however are super lightweight, so should just be a local variable used for construction of a single table, you can't reuse them.