Size of int and sizeof int pointer on a 64 bit machine
No, the sizeof(int)
is implementation defined, and is usually 4 bytes.
On the other hand, in order to address more than 4GB of memory (that 32bit systems can do), you need your pointers to be 8 bytes wide. int*
just holds the address to "somewhere in memory", and you can't address more than 4GB of memory with just 32 bits.
What the pointer size in 64 bits computer in C++?
Your executable is still being compiled as a 32-bit binary. Try compiling it as a 64-bit project.
The operating system makes no difference to the internal size of a pointer if the processor is emulating the program within a 32-bit environment...
In VS2010, head over to the configuration manager, make a new entry under 'platform', and select x64
(usually it's the only other option there)
EDIT: Also, make sure you're passing a void*
to the sizeof()
operator.
c++ pointer on 64 bit machine
The printing of addresses in most C++ implementations suppresses leading zeroes to make things more readable. Stuff like 0x00000000000013fd
does not really add value.
When you wonder why you will normally not see anything more than 48bit values in userspace, this is because the current AMD64 architecture is just defined to have 48bit of virtual address space (as can be seen by e.g. cat /proc/cpuinfo
on linux)
What is the benefit of larger pointers on 64-bit systems?
A pointer can hold the address of a single byte in memory. Based on its size you can calculate the maximum number of different values a given pointer can store.
With a pointer of 4 bytes (32 bits) you are limited to address only 4GB of memory, since:
2^32 = 4294967296
On the other hand, a 8 bytes (64 bit) pointer is able to address a much wider range of 17179869184GB theoretically:
2^64 = 18446744073709551616
This are 16EB (exabytes).
In practice, it is much less than that, because of limitations on most processors and the physical size of the memory etc.
You can read more on this topic here:
https://en.wikipedia.org/wiki/64-bit_computing#Limitations_of_practical_processors
Related Topics
C++ Virtual Function Table Memory Cost
The Cxx Compiler Identification Is Unknown
Simulating Mouse Clicks on MAC Os X Does Not Work for Some Applications
#Error Please Use the /Md Switch for _Afxdll Builds
Creating and Deallocating a Qt Widget Object
Is the Comma in a Variable List a Sequence Point
Immediate Exit of 'While' Loop in C++
In Which Versions of the C++ Standard Does "(I+=10)+=10" Have Undefined Behaviour
C++ Class Member Function Callback
Redirect Both Cout and Stdout to a String in C++ for Unit Testing
Should You Overload Swap in the Std Namespace
How to Determine If Returned Pointer Is on the Stack or Heap
Why Can't I Use <Experimental/Filesystem> with G++ 4.9.2
Freopen() Equivalent for C++ Streams
What Happens to the Memory Allocated by 'New' If the Constructor Throws
Can't Access Derived Class Method from Pointer of Type Base Class
Calling an Explicit Constructor with a Braced-Init List: Ambiguous or Not