Created by liqiang on 15/12/12.
| 4 | * Created by liqiang on 15/12/12. |
| 5 | */ |
| 6 | public class ClassSize { |
| 7 | |
| 8 | public static final int DefaultRecordHead; |
| 9 | public static final int ColumnHead; |
| 10 | |
| 11 | //objectHead的大小 |
| 12 | public static final int REFERENCE; |
| 13 | public static final int OBJECT; |
| 14 | public static final int ARRAY; |
| 15 | public static final int ARRAYLIST; |
| 16 | static { |
| 17 | //only 64位 |
| 18 | REFERENCE = 8; |
| 19 | |
| 20 | OBJECT = 2 * REFERENCE; |
| 21 | |
| 22 | ARRAY = align(3 * REFERENCE); |
| 23 | |
| 24 | // 16+8+24+16 |
| 25 | ARRAYLIST = align(OBJECT + align(REFERENCE) + align(ARRAY) + |
| 26 | (2 * Long.SIZE / Byte.SIZE)); |
| 27 | // 8+64+8 |
| 28 | DefaultRecordHead = align(align(REFERENCE) + ClassSize.ARRAYLIST + 2 * Integer.SIZE / Byte.SIZE); |
| 29 | //16+4 |
| 30 | ColumnHead = align(2 * REFERENCE + Integer.SIZE / Byte.SIZE); |
| 31 | } |
| 32 | |
| 33 | public static int align(int num) { |
| 34 | return (int)(align((long)num)); |
| 35 | } |
| 36 | |
| 37 | public static long align(long num) { |
| 38 | //The 7 comes from that the alignSize is 8 which is the number of bytes |
| 39 | //stored and sent together |
| 40 | return ((num + 7) >> 3) << 3; |
| 41 | } |
| 42 | } |