devxlogo

Reducing A Class’s Size

Reducing A Class’s Size

Many programmers still use the non-standard, platform dependent BOOL typedef instead of using bool. There are many good reasons why you shouldn’t use BOOL; one of them has to do with the size of this type. Unlike bool, which occupies one byte on most platforms, BOOL occupies four bytes. Thus, BOOL causes am unnecessary increase in the size of your classes and structs. Consider the following example:

 class Bloated{ BOOL a; BOOL b; BOOL c; BOOL d;};class Slim{ bool a; bool b; bool c; bool d;};

Class Bloated occupies 16 bytes in memory. Slim, on the other hand, occupies only four bytes.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist