Advertisement

Struct alignment and disk files

Started by February 07, 2000 03:14 AM
1 comment, last by Qoy 24 years, 7 months ago
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.
Advertisement
Thanks. I think I''ll just write each member by itself then, just in case (I''m using classes, not structs)

This topic is closed to new replies.

Advertisement