RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Optimize Your Member Layout

Optimization doesn't have to be more trouble than it's worth! This month's solution shows a drawback-free technique that minimizes the amount of padding inserted between your data members, increasing speed and saving memory.

s we all know, premature optimization is considered evil as it often entails eventually useless design complications and portability compromises. However, this doesn't mean that healthy programming habits should be completely ignored, especially when they are free of charge. This month's solution shows you an effective and simple technique that will help optimize the layout of your data structures (classes, structs, and unions) without sacrificing performance or incurring any design compromises. This technique is particularly useful in applications that manipulate a large number of objects, for example databases, CAD tools, directory services, graphical editors, and financial systems. It is also useful in memory-challenged environments such as embedded systems and mobile devices.

How to pack data members optimally so that memory isn't wasted and speed isn't lost?

Organize data members in a way that minimizes the amount of padding bytes inserted between them.

Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date