0

What is #pragma pack(1) in c++?

#pragma pack(1)

1st Mar 2017, 4:54 AM
Krishna Subhash Sonawane
Krishna Subhash Sonawane - avatar
2 Antworten
+ 1
#pragma pack(1) in c++ assures that all data members follow each other in the memory allignment without any padding. Typically when a class is defined in c++, the compiler will add padding between data members in order to ensure that the members follow a certain byte boundary. But when you use #pragma pack(1), you make sure that there is no padding between any of the elements. Memory alignment is important when it comes to performance however the compiler will make sure that your memory always has the most optimal allignment for your platform. You will very rarely want to use #pragma pack unless specified by an external library or code base.
5th Mar 2017, 5:21 PM
Alexandre Sabourin
Alexandre Sabourin - avatar
+ 1
Thnx bro
5th Mar 2017, 5:39 PM
Krishna Subhash Sonawane
Krishna Subhash Sonawane - avatar