gpt4 book ai didi

c# - 将大数据传递到 C# 函数的最佳方式是什么?

转载 作者:太空狗 更新时间:2023-10-30 00:32:36 25 4
gpt4 key购买 nike

基本上,我有一个非常大的 byte[] 和一类辅助函数。

如果我调用 Helpers.HelperFunc(mybigbytearray),我认为 mybigbytearray 会在内存中复制吗?

如果是这样,给函数一个大变量的最佳方法是什么(指针看起来不错,但使辅助函数不安全明智?垃圾收集器仍然有效吗?)

最佳答案

数组与 C# 中的其他对象一样,通过引用传递,因此数组中的数据不会重复;您将数组传递给的函数将引用原始数组。


来自 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.

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.

关于c# - 将大数据传递到 C# 函数的最佳方式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16624445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com