Suppose that I am in a 64-bit machine compiling a C program with gcc
. I'm assuming that sizeof(int)
is 8 bytes, and sizeof(char)
is 1 byte.
Because of memory alignment, the following struct:
struct example{
int a;
char c;
}
does not actually have a size of 9 bytes, but 16 (twice sizeof(int)
), so that both its beginning and ending addresses can be at multiples of the word size (assumed 8 bytes here).
I was wondering how large the following class would be in Java 8:
class Node {
int val;
Node left, right;
boolean flag;
}
I'm basically not certain whether we would align at multiples of 8 or 4 bytes.