Why #pragma pack(1)???
Posted: Tue Dec 27, 2022 6:28 pm
Why does PB align structures to a 1 byte boundary by default? There must be a good reason for that, right?!
http://www.purebasic.com
https://www.purebasic.fr/english/
Ok, maybe. But this downward "compatibility" forces me to add Align #PB_Structure_AlignC to every structure I create, just (in case) to get proper padding. Internal structures are already padded by PB (PB_Alignment) so adding pack(1) makes sense, but my own structures shouldn't be packed by default...PeDe wrote: Tue Dec 27, 2022 7:06 pm Maybe for compatibility with Visual Basic <= 5. Only later VB6 used the C standard with user types.
I'm a neofitos on this matterchi wrote: Tue Dec 27, 2022 8:05 pm ...forces me to add Align #PB_Structure_AlignC to every structure I create...
Aligned memory access is faster than unaligned...
I know there are situations where structure packing is useful (e.g. sending data over tcp/udp), but most of the time I would prefer performance over size.mk-soft wrote: Tue Dec 27, 2022 8:12 pm I hope it stays that way. I use a lot of structures for communication. I also use overlays of structures a lot.
They have to be packed 1 like this.
All structure and variable memories are aligned in Pure Basic. Only the fields itself become unaligned when non-processor-word fields are included. However, if you prefer performance over size, you would anyway use always integers and doubles instead of bytes, words, longs, etc.