Struct alignment and disk files
If I put a #pragma pack around any structures or classes I plan on saving to disk, then will that make it safe to just write the whole structure at one time, or will it still be safer to write each element individually?
------------------------------
Jonathan Little
invader@hushmail.com
http://www.crosswinds.net/~uselessknowledge
If it''s your own data structure, it should be safe to write the whole struct, no matter how it''s aligned. For predefined data structures, e.g. Bitmap headers, you should pack it.
I don''t recommend ever writing classes as blocks of memory, as with an fwrite or other similar function. The "contract" stating what an class looks like in memory is a lot looser than the than the one stating what a struct looks like in memory.
I don''t recommend ever writing classes as blocks of memory, as with an fwrite or other similar function. The "contract" stating what an class looks like in memory is a lot looser than the than the one stating what a struct looks like in memory.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement