Machine addresses
Many data structures involve representation of machine addresses.
The typical x64 architectures we widely used, need 8 bytes to represent address.
Many older machines use a 32-bit architecture that
would involve just 4 bytes per machine address.
Primary type
type | bytes |
---|---|
byte | 1 |
boolean | 1 |
char | 2 |
int | 4 |
float | 4 |
double | 8 |
long | 8 |
Object
The overhead
includes:
- a reference to the object’s class
- garbage collection information
- synchronization information
List
LinkedList:
Instance :
- 16 bytes of object overhead
- 8 bytes for first node reference
- 4 bytes counter
- 4 bytes padding
Node :
- 16 bytes of object overhead
- 8 bytes for the references to the Item
- 8 bytes for the next to the Item
- 8 bytes for the extra overhead
total :
32 + (40 + size(Ojbect)) * N
Array
type | bytes |
---|---|
int[N] | 24 + 4N |
Integer[N] | 24 + 32N |
int[M][N] | 24 + 8 * (24 + 4N) |
Integer[M][N] | 24 + 8 * (24 + 32N) |
String
1 | // 16 bytes |
Total : 64 + 2N
HashMap
array length : M
average node size : N
Total[structure] : 64M + 48N
Tree
Total[structure] : 56N