:
public class List<T> : IList<T>, ICollection<T>, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
{
private T[] _items; //4 bytes for x86, 8 for x64
private int _size; //4 bytes
private int _version; //4 bytes
[NonSerialized]
private object _syncRoot; //4 bytes for x86, 8 for x64
private static readonly T[] _emptyArray; //one per type
private const int _defaultCapacity = 4; //one per type
...
}
你有總的在x86 字節(16 List<T>
成員和4元數據參考開銷)和在x64 ,包括reffernce到類型的對象,該對象在.NET每個對象具有的。這個計算大致上不算數。
public class Dictionary<TKey, TValue> : ...
{
private int[] buckets; //4 bytes for x86, 8 for x64
private Dictionary<TKey, TValue>.Entry[] entries; //4 bytes for x86, 8 for x64
private int count; //4 bytes
private int version; //4 bytes
private int freeList; //4 bytes
private int freeCount; //4 bytes
private IEqualityComparer<TKey> comparer; //4 bytes for x86, 8 for x64
private Dictionary<TKey, TValue>.KeyCollection keys; //4 bytes for x86, 8 for x64
private Dictionary<TKey, TValue>.ValueCollection values; //4 bytes for x86, 8 for x64
private object _syncRoot; //4 bytes for x86, 8 for x64
private const string VersionName = "Version"; //one per type
private const string HashSizeName = "HashSize"; //one per type
private const string KeyValuePairsName = "KeyValuePairs"; //one per type
private const string ComparerName = "Comparer"; //one per type
}
x86和針對x64。再次粗略計算,因爲需要不同對象的實例。
我認爲你最好的選擇是使用像ANTS這樣的內存分析器,並查找這些特定對象及其內存使用情況。 – Kippie 2013-04-21 13:34:35
我沒有錢螞蟻和自動取款機我在ubuntu – Petr 2013-04-21 13:35:41
我認爲在幾乎所有情況下,答案是「這麼小,它並不重要」。 – svick 2013-04-21 13:55:31