gpt4 book ai didi

c# - 内存是如何在int数组中分配的

转载 作者:搜寻专家 更新时间:2023-10-31 19:28:38 24 4
gpt4 key购买 nike

一个int数组占用多少空间?或者 int 数组占用多少空间(以字节为单位),看起来像这样:

 int[] SampleArray=new int[]{1,2,3,4};

内存分配语言是特定的吗??

谢谢大家

最佳答案

既然你加了很多语言标签,我想写C#。在 C# 中,这取决于操作系统。

对于 32 位,每个 int 是 4 字节,4 字节也是对象的引用,所以 4 * 4 + 4 = 20 字节

对于 64 位,每个 int 是 4 字节和 8 字节也用于引用对象,所以 4 * 4 + 8 = 24 字节

来自 C# 5.0 in a Nutshell在第 22 页;

Each reference to an object requires an extra four or eight bytes, depending on whether the .NET runtime is running on a 32- or 64-bit platform.

关于c# - 内存是如何在int数组中分配的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19049336/

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