简体   繁体   中英

flatbuffers: Is it possible to delete a buffer via root-pointer

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM