Why #pragma pack(1)???

Everything else that doesn't fall into one of the other PB categories.
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Why #pragma pack(1)???

Post by chi »

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
PeDe
Enthusiast
Enthusiast
Posts: 286
Joined: Sun Nov 26, 2017 3:13 pm

Re: Why #pragma pack(1)???

Post by PeDe »

Maybe for compatibility with Visual Basic <= 5. Only later VB6 used the C standard with user types.

Peter
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Re: Why #pragma pack(1)???

Post by chi »

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.
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...
Et cetera is my worst enemy
User avatar
Caronte3D
Addict
Addict
Posts: 1361
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: Why #pragma pack(1)???

Post by Caronte3D »

chi wrote: Tue Dec 27, 2022 8:05 pm ...forces me to add Align #PB_Structure_AlignC to every structure I create...
I'm a neofitos on this matter :? Which is the purpose of doing that?
User avatar
mk-soft
Always Here
Always Here
Posts: 6246
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Why #pragma pack(1)???

Post by mk-soft »

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.
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
User avatar
chi
Addict
Addict
Posts: 1087
Joined: Sat May 05, 2007 5:31 pm
Location: Austria

Re: Why #pragma pack(1)???

Post by chi »

Caronte3D wrote: Tue Dec 27, 2022 8:11 pm
chi wrote: Tue Dec 27, 2022 8:05 pm ...forces me to add Align #PB_Structure_AlignC to every structure I create...
I'm a neofitos on this matter :? Which is the purpose of doing that?
Aligned memory access is faster than unaligned...
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.
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.
Et cetera is my worst enemy
User avatar
STARGÅTE
Addict
Addict
Posts: 2234
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Why #pragma pack(1)???

Post by STARGÅTE »

chi wrote: Tue Dec 27, 2022 9:04 pm
Caronte3D wrote: Tue Dec 27, 2022 8:11 pm
chi wrote: Tue Dec 27, 2022 8:05 pm ...forces me to add Align #PB_Structure_AlignC to every structure I create...
I'm a neofitos on this matter :? Which is the purpose of doing that?
Aligned memory access is faster than unaligned...
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 moreTypeface - Sprite-based font include/module
Post Reply