// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace E { public class C1 { } public class C2 { public int v; } public class C3 { public int a; public int b; public int c; public int d; } public class Program { private static long MemUsed() { return GC.GetTotalMemory(true); } public static void Test(int n) where T : new() { T[] a = new T[n]; long m1 = MemUsed(); for(int i = 0; i < a.Length; i++) { a[i] = new T(); } long m2 = MemUsed(); Console.WriteLine(typeof(T).Name + " : " + (m2 - m1) / n + " bytes/object"); } public static void Main(string[] args) { for(int i = 1; i <= 1000000; i *= 10) { Test(i); Test(i); Test(i); } Console.WriteLine("Done"); } } }