-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Open
Labels
Description
I think its almost possible today to write an API like the following to make it easier to efficiently build vectors of tables. The only problem is that CreateUninitializedVector asserts that the passed type is a scalar.
Are there any other issues I'm not seeing with such an API? Do the maintainers think something with this shape would be helpful to add to avoid needing out of band storage for vectors of tables?
template <typename T>
class VectorBuilder {
using VecOffset = Offset<Vector<Offset<T>>;
public:
VectorBuilder(FlatBufferBuilder& fbb, size_t size) : size_(size), vector_(fbb.CreateUninitializedVector(size_, &start_)) {}
void Push(Offset<T> elt) {
assert(written_ < size_);
*(start + written_) = elt;
++written_;
}
VecOffset Finish() {
assert(written_ == size_);
return vector_;
}
private:
const size_t size_;
Offset<T>* start_;
const VecOffset vector_;
size_t written_ = 0;
};
Reactions are currently unavailable