0

I'm starting to use the flatbuffer library. But there is a thing that feels uncomfortable for me, when it comes to delete a buffer. I don't know ho to delete buffer via it's root-pointer-element. If this were possible the root-pointer could take the ownership of the allocated space and i've not to bother about lifetime-issues(dangling root-pointer, memory-leaks,...)

std::uint_8* buffer = get_buffer_for_exaple_from_file("my_monster.bin");
auto monster = MyGame::Sample::GetMonster(buffer);
///monster points somewhere in buffer

...

///now this would be very handy
delete_buffer(monster);                 ///buffer is deleted

Q: Is it possible (maybe under some restrictions as monster is not mutable, etc) write something like delete_buffer

Kara
  • 6,115
  • 16
  • 50
  • 57
user1235183
  • 3,002
  • 1
  • 27
  • 66

1 Answers1

0

The root pointer points to a location inside the buffer that is not at a known offset, so no, you can't delete the buffer through it. To delete the buffer, you must use the original buffer pointer.

Aardappel
  • 5,559
  • 1
  • 19
  • 22