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;