Allocating 32-bit integer arrays in 64-bit machines

Posted by Shredderroy on Stack Overflow See other posts from Stack Overflow or by Shredderroy
Published on 2012-04-05T05:25:46Z Indexed on 2012/04/05 5:30 UTC
Read the original article Hit count: 138

Filed under:
|

I have a 64-bit i7 machine. Suppose I allocate memory for n 32-bit integers. How many physical registers will actually be used in the allocation: n, or n/2?

I tried to write the following simple programme to find out.

#include <iostream>
#include <cstdlib>

using namespace std;

int main (int argc, char *argv[]) {
    int a[4];
    cout << &a[0] << "\t" << &a[3] << endl;
    cin.ignore (1);
    return 0;
} // End main ()

The output is:

0018FA04        0018FA10

They seem further apart than they should be. Why aren't the addresses 04 and 07? And does this mean that the system is actually allocating four (or more) integers, instead of packing the four 32-bit integers into two 64-bit registers?

Thanks in advance for your help.

© Stack Overflow or respective owner

Related posts about c++

Related posts about memory-management