What is the best way to pass big data in C # functions?

Basically, I have a very large byte[] and a class of helper functions.

How do I understand correctly, if I call Helpers.HelperFunc(mybigbytearray) , will mybigbytearray be duplicated in memory?

If so, what is the best way to give a large function variable (pointers look good, but make unsafe helper functions wise? Will the garbage collector work?)

+4
source share
1 answer

Arrays, like other objects in C #, are passed by reference, so no data inside the array will be duplicated; the function with which you pass the array will have a reference to the original array.


From Arrays as Objects (C # Programming Guide)

In C #, arrays are actually objects, not just addressable areas of contiguous memory, as in C and C ++. System.Array is the abstract base type of all array types.

and Passing Arrays as Arguments (C # Programming Guide)

Arrays can be passed as arguments to method parameters. Since arrays are reference types, a method can change the value of elements.

+8
source

Source: https://habr.com/ru/post/1481520/