dimanche 5 mars 2017

Why is difference between allocated variables addresses 16 byte?

Why is there aligment to 8 bytes (and 16 on 64bit systems)? What are reasons for such alignment?

Example:

int* ptr1 = new int;
int* ptr2 = new int;
int* ptr3 = new int;

cout << ptr1 << " " << ptr2 << " " << ptr3 << endl;
cout << ptr2 - ptr1 << endl;

Outputs:
0x15cbc20 0x15cbc40 0x15cbc60
8

Aucun commentaire:

Enregistrer un commentaire