benjist benjist - 1 year ago 104
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.

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download