Why #pragma pack(1)???
Why #pragma pack(1)???
Why does PB align structures to a 1 byte boundary by default? There must be a good reason for that, right?!
Et cetera is my worst enemy
Re: Why #pragma pack(1)???
Maybe for compatibility with Visual Basic <= 5. Only later VB6 used the C standard with user types.
Peter
Peter
Re: Why #pragma pack(1)???
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.
Et cetera is my worst enemy
Re: Why #pragma pack(1)???
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...

Re: Why #pragma pack(1)???
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.
They have to be packed 1 like this.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: Why #pragma pack(1)???
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.
Et cetera is my worst enemy
Re: Why #pragma pack(1)???
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.
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module
Lizard - Script language for symbolic calculations and more ― Typeface - Sprite-based font include/module