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:
- make old array eligible garbage collection, , deallocate it
- allocate new array
- fill new array zeros.
when keep old array, c# will
- fill old array zeros.
everything else being equal, second approach more efficient.
Comments
Post a Comment