Consider the class below, and notice the comment telling how much bytes they use.
There is a overhead of 16bytes for maintaining class, 1 Byte for byte and boolean, 2Byte for char and short, 4 bytes for integer, 8 bytes for long and double, and some overhead for padding, to make overall memory even, to sum up:
Java type | Bytes required |
---|---|
boolean | 1 |
byte | |
char | 2 |
short | |
int | 4 |
float | |
long | 8 |
public class MysteryBox { // 16 (object overhead) private int x0; // 4 (1 int) private long y0, y1, y2; // 24 (3 long) private double z0, z1, z2; // 24 (3 double) private boolean[] a = new boolean[80]; // 8 (reference to array) // 104 (boolean array of size 80) ... 4 (padding) } ---- //total size - 184
Here are some good links on java memory objects:
0 comments:
Post a Comment