相关疑难解决方法(0)

.NET数组的开销?

我试图使用以下代码确定.NET数组(在32位进程中)标头的开销:

long bytes1 = GC.GetTotalMemory(false);
object[] array = new object[10000];
    for (int i = 0; i < 10000; i++)
        array[i] = new int[1];
long bytes2 = GC.GetTotalMemory(false);
array[0] = null; // ensure no garbage collection before this point

Console.WriteLine(bytes2 - bytes1);
// Calculate array overhead in bytes by subtracting the size of 
// the array elements (40000 for object[10000] and 4 for each 
// array), and dividing by the number of arrays (10001)
Console.WriteLine("Array overhead: {0:0.000}", 
                  ((double)(bytes2 - bytes1) - …
Run Code Online (Sandbox Code Playgroud)

.net c# arrays overhead

36
推荐指数
2
解决办法
7944
查看次数

标签 统计

.net ×1

arrays ×1

c# ×1

overhead ×1