// 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) 
public class Sizeof {
    private final static int N = 10000000;
    public static long mem() {
        System.gc();
        Runtime rt = Runtime.getRuntime();
        return rt.totalMemory() - rt.freeMemory();
    }
    public static void main(String[] args) {
        long m1 = mem();
        byte[] ba = new byte[N];
        long m2 = mem();
        System.out.println("sizeof byte = " + (m2 - m1)*1.0/N);
    }
}
