benjist benjist - 3 months ago 27
C++ Question

How to properly delete a FlatBuffer object read from disk

I read compressed data from disk, uncompress it, and create a "Cell" object that was generated from a FlatBuffer scheme.

Cell* getCell(int x, int y, int z) {
// ...
return GetCell(buffer); // buffer is an inflated uint_8 data array

So far so good. But how can I delete the item? Since it's not possible to access the buffer data later on.


You'll need to hold on to the buffer separately to be able to delete it, as you cannot derive a buffer pointer from a root pointer (in this case Cell *). As you say yourself, you cannot destruct a Cell * either, as it doesn't own that memory.