Basically, I have a very large byte[]
and a class of helper functions.
Am I right in thinking if I call Helpers.HelperFunc(mybigbytearray)
, mybigbytearray
will be duplicated in memory?
If so, what's the best way to give a big variable to a function (pointers look good but is making the helper functions unsafe
wise? Would the garbage collector still work?)
Arrays, like other objects in C#, are passed by reference, thus no data inside the array will be duplicated; the function you pass the array to will have a reference to the original array.
From Arrays as Objects (C# Programming Guide)
In C#, arrays are actually objects, and not just addressable regions 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. Because arrays are reference types, the method can change the value of the elements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With