Bool and bool efficiency problems

Source: Internet
Author: User

Someone on the Internet said that bool is more efficient than bool. I don't understand, so I checked it online. Now I will summarize it. I don't know if it is correct.

-------------------------------------------------------------------------------
First, write in VCCodeTest the size of these two types. The Code is as follows:
Cstring temp;
 
Temp. Format ("% d", sizeof (bool ));
Trace ("/R/n ---------------------/R/N ");
Trace ("in VC ++ bool's size is :");
Trace (temp );
Trace ("/R/n ---------------------/R/N ");
 
Temp. Format ("% d", sizeof (bool ));
Trace ("/R/n ---------------------/R/N ");
Trace ("in VC ++ bool's size is :");
Trace (temp );
Trace ("/R/n ---------------------/R/N ");

The running result is as follows:
-----------------------
In VC ++ bool's size is: 1
-----------------------

-----------------------
In VC ++ bool's size is: 4
-----------------------

bool occupies 4 bytes and bool occupies 1 byte.
I thought the computer would process 1 byte faster than 4 bytes. In fact, from time to time.
because the current CPU is 32-bit, the CPU processes 4 bytes at a time, so processing 1 byte requires additional processing.
therefore, the efficiency is low.
typedef char bool
typedef DWORD bool

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.