kaitai_struct_cpp_stl_runtime icon indicating copy to clipboard operation
kaitai_struct_cpp_stl_runtime copied to clipboard

Why was `read_bytes(char* ...)` removed?

Open Wyverex42 opened this issue 2 years ago • 1 comments

I started using Kaitai two years ago when it was still version 0.8. After a long project hiatus I've now upgraded to 0.10 and noticed that the read_bytes(char*, std::streamsize) variant was removed. This is an issue for writing code that tries to avoid excessive memory allocations.

For the binary format I'm reading, Kaitai allocates a lot of small memory blocks and I ran into a "death by a thousand cuts" situation where parsing was extremely slow due to all those allocations. So I wrote a custom type that preallocated memory for certain regions of the file and parsing basically became instant.

Now that the char* variant of read_bytes was removed, I'm back to square one, unfortunately, and I can't avoid allocating memory when reading a block of bytes because I can only receive a new std::string instance as a return value.

Why was this decision made and could this be reversed?

Thank you!

Wyverex42 avatar Mar 25 '23 08:03 Wyverex42

Nvm, I just realized this function was never a part of this library in the first place and I added it myself precisely to avoid those allocations!

This might be a worthwhile addition to the interface.

Wyverex42 avatar Mar 25 '23 08:03 Wyverex42