異なるデータストレージ構造のメモリ消費量の比較

Javaの異なる構造は、異なる量のメモリを消費します。 したがって、最も効率的なデータ保存方法の選択は私たちにとって非常に重要です。

`new int [1024]`と `new Integer [1024]`コンストラクトのメモリ消費量の違いは何ですか?

int[] ints = new int[1024];
for (int i = 0; i < ints.length; i++) ints[i] = i;

Integer[] ints = new Integer[1024];
for (int i = 0; i < ints.length; i++) ints[i] = i;


注:整数型の値の1/8はキャッシュされ、余分なメモリを消費しません。 ブール型およびバイト型のすべての値もキャッシュされます。

構造JVM 32ビット(バイト単位のサイズ)JVM 64ビット(バイト単位のサイズ)
new BitSet(1024)168168
new boolean[1024]10401040
new Boolean[1024]41124112
new ArrayList<Boolean>(1024)41364136
1024のnew LinkedList<Boolean>()2462424624
new byte[1024]10401040
new Byte[1024]41124112
new ArrayList<Byte>(1024)41364136
1024のnew LinkedList<Byte>()2462424624
new char[1024]20642064
new Character[1024]1844818448
new short[1024]20642064
new Short[1024]1844818448
new ArrayList<Character/Short>(1024)1847218472
new LinkedList<Character/Short>() with 10243896038960
new int[1024]41124112
new Integer[1024]1844818448
new float[1024]41124112
new Float[1024]2049620496
new ArrayList<Integer/Float>(1024)1847218472
new LinkedList<Integer/Float>() with 10243896038960
new long[1024]82088208
new Long[1024]1844825616
new double[1024]82088208
new Double[1024]2049628688
new ArrayList<Long/Double>(1024)1847225640
new LinkedList<Long/Double>() with 10243896046128
new String[1024]5246461456
new ArrayList<String>(1024)5248861480
1024のnew LinkedList<String>()7297681968


完全なコードはこちらから入手できます。

Z.Y. おそらく、すべてのJAVA開発者はこれをすべて知っている必要がありますが、誰かが知らない場合は、 笑顔で手を振って、読んで覚えてください:)

Source: https://habr.com/ru/post/J124909/


All Articles