c# - Should I create a new array or use array.clear? -


i have array of data gets zeroed out time time. that, should instantiate new array, or use array.clear method?

for instance,

int workingset = new int[5000];  // other code here  workingset = new int[5000]; // or array.clear(workingset, 0, 5000); 

when make new array instead of old one, c# will:

  1. make old array eligible garbage collection, , deallocate it
  2. allocate new array
  3. fill new array zeros.

when keep old array, c# will

  1. fill old array zeros.

everything else being equal, second approach more efficient.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -