Hello,
Assume if I have an array of size 78719476736 bytes. mind you that this array is dynamically allocated using malloc in my C code. Assume malloc returns a valid pointer after allocating this much memory. The size of this array is more than UINT_MAX(4294967295) , i.e. max limit of a unsigned int(32 bits)
Assume my code looks like something below e.g.
int *buf;
buf = (int*)malloc(78719476736);
Here 78719476736 is greater than 4 * UINT_MAX.
Now if i have to refer to all the elements of buf, then since buf is int* it will be 32 bit, so it will not be able to address all the memory elements which i have allocated using malloc(78719476736 bytes).
My question is shouldn't the code above be changed to make buf as long long(64 bit variable) as only a long long variable will be able to address the large memory that i have allocated.
Changed code e.g.
unsigned long long int buf;
buf = (unsigned long long int*)malloc(78719476736);
In fact i think, variable buf should not be a pointer any more as any pointer is going to be 32 bit wide and hence it will not be able to access 78719476736 bytes.
So it should be a plain unsigned long long int and i will have to cast the malloc return pointer value to an unsigned long long int as shown in the changed code above and use buf to access all the elements allocated.
Am i correct in my assumptions above ?
or
Am i confusing/missing something?
EDIT: If it helps,
I am working on a Desktop having WinXP on a Intel Core 2 Duo(64 bit CPU). So CPU wise it should not be a problem accessing more than 4 GB address space. What all other components should be enabled for 64 bit support , i.e.
a.) How do i enable compiler support for 64 bit while compiling(I am using Visual Studio 2005 Professional edition)
b.) OS support for 64 bit - I am using Windows XP Professional.
Thank You.
-AD.