C++ Pointer on 64 Bit MAChine

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



Leave a reply



Submit