How to properly delete a FlatBuffer object read from disk

时间:2016-10-15 17:22:06

标签: c++ flatbuffers

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.

1 个答案:

答案 0 :(得分:1)

您需要单独保留缓冲区才能删除它,因为您无法从根指针(在本例中为Cell *)派生缓冲区指针。正如你自己所说,你也不能破坏Cell *,因为它没有拥有那个记忆。

编辑:显然,这样的功能是可行的,请参阅:https://github.com/google/flatbuffers/commit/6862b2ff08021c7ba474334a6e2a3f3b1fc0dee5 这从根指针派生缓冲区指针。