void foo(Node* p[], int size){
_uint64 arr_of_values[_MAX_THREADS];
for (int i=0 ; i < size ; i++ ){
arr_of_values[i] = p[i]->....;
// much code here
//
}
}
对比
void foo(Node* p[], int size){
_uint64 arr_of_values[_MAX_THREADS];
Node* p_end = p[size];
for ( ; p != p_end ; ){
arr_of_values[i] = (*p)->.....;
p++;
// much code here
//
}
}
我创建了这个函数来演示我在问什么:
从缓存效率方面来看,什么更有效:采用 p[i] 还是使用 *p++?
(我永远不会在其余代码中使用 p[ix],但我可以在以下计算中使用 p[i] 或 *p)