我在C#中使用数组,如下所示:class abc {xyz x = new xyz(); // some other classpublic double [] arr = new double [100]; // Allocated 400 bytes // for this array.// 100 is imaginary size // shown here fo...
我在C#中使用数组,如下所示:
class abc
{
xyz x = new xyz(); // some other class
public double [] arr = new double [100]; // Allocated 400 bytes
// for this array.
// 100 is imaginary size
// shown here for simplicity.
// Actual size will depend on input.
private void something()
{
x.funA(arr);
}
}
在上面的abc类中,数组消耗400个字节.现在,我已将此数组作为某些参数传递给类xyz中的参数.
我的问题是,是否将在类xyz中分配新的400字节. 400字节不是什么大问题,但是在我的程序中,我正在传递占用一个MB的数组.
解决方法:
存储引用所需的内存量.据我所知,在32位计算机上为8字节,在64位计算机上为12字节.
沃梦达教程
本文标题为:当我们将其传递给函数作为参数时,此数组将在C#中占用多少内存
猜你喜欢
- C#使用HttpHelper框架重启路由器 2023-06-21
- Unity实现高效的音效管理类的示例代码 2023-07-18
- C# 如何合并和拆分PDF文件 2023-03-29
- C#实现WPF项目复制和移动文件夹 2023-05-26
- Unity3D实现模型淡入淡出效果 2023-01-16
- C# 9.0 新特性之模式匹配简化的实现 2023-03-04
- C# 使用Tcp/Udp协议的示例代码 2023-03-09
- C#中图片.BYTE[]和base64string的转换方法 2022-10-27
- 对C# 多态的理解 2023-03-10
- C# 将数据库SqlServer数据绑定到类中的过程详解 2023-06-15