// 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 Sizer where T : class,new() { private const int N = 100000; public static int Calc() { GC.Collect(); long m1 = GC.GetTotalMemory(false); T[] a = new T[N]; for(int i = 0; i < N; i++) { a[i] = new T(); } long m2 = GC.GetTotalMemory(false); return (int)((m2 - m1) / N); } } public class A { private int iv; public int Iv { get { return iv; } set { iv = value; } } } public class B { private int iv; private double xv; public int Iv { get { return iv; } set { iv = value; } } public double Xv { get { return xv; } set { xv = value; } } } public class C { private int iv; public int Iv { get { return iv; } set { iv = value; } } public virtual void Foo() { } public virtual void Bar() { } } public class Program { public static void Main(string[] args) { Console.WriteLine(Sizer.Calc()); Console.WriteLine(Sizer.Calc()); Console.WriteLine(Sizer.Calc()); } } }