workMethods(ref myArray)与workMethods(myArray)之间的内存使用差异? [英] Memory usage difference between workMethods(ref myArray) vs workMethods(myArray) ?

查看:81
本文介绍了workMethods(ref myArray)与workMethods(myArray)之间的内存使用差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

What is Memory usage difference between  workMethods(ref myArray)  vs  workMethods(myArray) ?





什么关于内存使用的这两个方法调用之间的区别是什么??





What is difference between this two method calls regarding memory usage ??

int[] myArray = new myArray[2000];

for(int i=0; i < myArray.Length; i++)
{
 myArray[i] = i;
}





然后将此数组传递给2个方法,这些方法将int类型数组作为进程的参数





then Pass this array to 2 methods which take int type array as parameter for process

workMethods(ref myArray);





和这种方法





and this method

workMethods(myArray);

推荐答案

没什么。



数组是一种崇敬的类型 - 它们总是如此 - 所以那就是每个传入方法的都是一个参考 - 这个很小(4或8个字节,取决于操作系统大小)



使用 ref keyword是指传递 持有 引用的变量,还是其副本。在第一种情况下,对变量的任何更改都将反映在方法之外的世界中,而没有 ref 他们不会。

In在这两种情况下,对数组中值的任何更改都将影响现有实际数据的唯一副本。
Nothing.

The array is a reverence type - they always are - so all that is every passed into the method is a reference - which is pretty small (4 or 8 bytes depending on OS size)

The only difference when using the ref keyword is whether the variable holding the reference is passed through, or a copy of it. In the first case, any changes to the variable will be reflected in the world outside the method, without the ref they won't.
In both cases, any changes to the values in the array will affect the one and only copy of the actual data in existence.


这篇关于workMethods(ref myArray)与workMethods(myArray)之间的内存使用差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆