Clean up file io, using filebuf and avoid double buffering
- filebuf usage (avoids formatting - a bit faster)
{
std::filebuf file;
auto result = file.open("test.bin", std::ios_base::in | std::ios_base::binary);
if (result == nullptr)
{
/* Handle error */
}
auto bytes_read = file.sgetn(reinterpret_cast<char*>(&read_value),
sizeof(read_value));
if (bytes_read < sizeof(my_value))
{
/* Handle partial read */
}
}
-
file size detection is error-prone https://gitlab.gwdg.de/irp/moench/-/blob/master/source/moench.h#L264
-
custom
inbuf
(https://gitlab.gwdg.de/irp/moench/-/blob/master/source/moench.h#L277) is not needed because ifstream/filebuf uses a buffer internally. Since it complicates the logic tremendously, get rid of it.
Edited by Leon Merten Lohse