3 ms·
You can absolutely save data like that, it's just that it's a terrible idea. There are obvious portability concerns issues: little-endian vs. big endian, 32-bit
by OskarS 1y ago
You can absolutely save data like that, it's just that it's a terrible idea. There are obvious portability concerns issues: little-endian vs. big endian, 32-bit vs. 64-bit, struct padding, etc.
Essentially, this system works great if you know the exact hardware and compiler toolchain, and you never expect to upgrade it with things that might break memory layout. Obviously this does not hold for Word: it was written originally in a 32-bit world and now we live in a 64-bit one, MSVC has been upgraded many times, etc. There's also address space concern: if you embed your pointers, are you SURE that you're always going to be able to load them in the same place in the address space?
The overhead of deserialization is very small with a properly written file format, it's nowhere near worth the sacrifice in portability. This is not why Word is slow.
- skywal_l 1y agoAndrew Kelley (author of zig) has a nice talk about programming without pointers allowing ultra fast serialize/deserialization. [0] And then you have things like cap'n'proto if you want to control your memory layout. [1] But for "productivity" files, you are essentially right. Portability and simplicity of the format is probably what matters. [0]: https://www.hytradboi.com/2025/05c72e39-c07e-41bc-ac40-85e8308f2917-programming-without-pointers https://www.hytradboi.com/2025/05c72e39-c07e-41bc-ac40-85e83... [1]: https://capnproto.org/ https://capnproto.org/
- OskarS 1y agoThat is true, cap’n proto and flatbuffers are excellent realizations of this basic concept. But that’s very different thing from what the commenter is talking about Word doing in the 90s, of just memory-mapping the internal data structures and be done with it.
- actionfromafar 1y agoSmalltalk is something like that.
- amelius 1y agoIt's only a terrible idea because our tools are terrible. That's exactly the point! (For example, if Rust would detect a version change, it could rewrite the data into a compatible format, etc.)
- johngossman 1y agoAt which point you're not just memory mapping the file. And if the new version changes the size of the object, it doesn't pack in the same place in memory, so you have to repack before saving. Even serializing with versioning is very hard. Memory mapping is much worse. Several other comments indicate that I am not the only one with bad experiences here.