相关疑难解决方法(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
查看次数

C# - 字符串实际上是一个字符数组还是只有一个索引器?

由于在C#中可以使用以下代码,因此我认为string是否实际上是一个chars数组:

string a="TEST";
char C=a[0]; // will be T
Run Code Online (Sandbox Code Playgroud)

c# arrays string

16
推荐指数
4
解决办法
6515
查看次数

标签 统计

arrays ×2

c# ×2

.net ×1

overhead ×1

string ×1