I was wondering if someone could explain to me what the #pragma pack
preprocessor statement does, and more importantly, why one would want to use it.
I
I have seen people use it to make sure that a structure takes a whole cache line to prevent false sharing in a multithreaded context. If you are going to have a large number of objects that are going to be loosely packed by default it could save memory and improve cache performance to pack them tighter, though unaligned memory access will usually slow things down so there might be a downside.