Re: bool vs BOOL



The reason "bool" requires more overhead than the "BOOL" type is
because of the size differences (which were already addressed in Carl's
reply). The performance difference comes from a machine architecture
point of view.

A CPU is best at handling its native data size. On most desktops
today, that tends to be a 32-bit value. That is why most memory
copying/moving algorithims copy memory one byte at a time until they
hit an 32-bit boundary, and then copy the memory in as many 32-bit
chunks as possible.

When dealing with values like "bool", that value must be "masked" at
some point (or even at multiple points) when loaded into or saved from
a register in order to "hide" the unused bits of the value. The
masking is just another step that the CPU would not normally have to
take. (Also note that this performacne difference may be *VERY*
CPU-specific, both on CPU vendor and the CPUs microarchitecture.)

My opinion, take it or leave it, is that there are many more problems
in software development that need to be addressed (like the unnecessary
abuse of dynamically allocated memory, and other poor practices), that
have much more of a performance implication than using a "bool" over a
"BOOL". Personally, I minmize my use of heap memory whenever possible,
but I still use "bool" instead of BOOL in my objects, as parameters,
and variables. If you are experiencing a performance problem, I would
look for lower hanging fruit before changing all my "bool"s to
"BOOL"s...

Peace!

-=- James.

.