【发布时间】:2011-08-20 09:00:01
【问题描述】:
从内存访问的角度来看...是否值得尝试这样的优化?
int boolean_value = 0;
//magical code happens and boolean_value could be 0 or 1
if(boolean_value)
{
//do something
}
代替
unsigned char boolean_value = 0;
//magical code happens and boolean_value could be 0 or 1
if(boolean_value)
{
//do something
}
与整数 4 相对的 unsigned char 当然只占用 1 个字节(假设这里是 32 位平台),但我的理解是处理器从内存中读取整数值会更快。
【问题讨论】:
标签: c optimization