There are two ways to zero out an integer/float array:
memset(array, 0, sizeof(int)*arraysize);
or:
for (int i=0; i <arraysize; ++i)
array[i]=0;
obviously, memset is faster for large arraysize
. However, at what point is the overhead of memset actually larger than the overhead of the for loop? For example, for an array of size 5 - which would be best? The first, the 2nd, or maybe even the un-rolled version:
array[0] = 0;
array[1] = 0;
array[2] = 0;
array[3] = 0;
array[4] = 0;
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…