flâneur — a map of the web's best reading

C++ Memory alignment - should we care? - Stack Overflow

stackoverflow.com · 1,482 words · saved by 1 readers

According to C++ Alignment, Cache Line and Best Practice and Data structure alignment, it should be better/faster and much more compact to write this: The members are declared in the order of the alignment size, starting with the highest alignment. Is it safe to say it is a good idea to order the declaration of the data members by alignment size? Would you say it is best practice? Or does it make no difference? (I heard that the compiler can not rearrange the defined order, due to the C++ standard, and this even holds for all data members declared in access specifier blocks of a class) Because I never read about this, neither in Scott Meyers' books nor in Bjarne Stroustrup's books, I wonder if I should start reordering the data declarations by alignment for my day-to-day work. This is more complicated than it may seem. By ordering your members according to alignment needs you'll save some padding bytes and the total size will be smaller. This may be important to you if memory is tight

C++ Memory alignment - should we care? - Stack Overflow New: Stack Overflow For Agents. The next generation of knowledge exchange. Learn more Collectives™ on Stack Overflow Find centralized, trusted content and collaborate around the technologies you use most. Learn more about Collectives Stack Internal Knowledge at work Bring the best of human thought and AI automation together at your work. Explore Stack Internal C++ Memory alignment - should we care? [duplicate] Ask Question Asked 6 years, 10 months ago Modified 6 years, 7 months ago Viewed 5k times 14 This question already has answers here

Explore this link on the map →

saved by

related reading