What is inside a pointer on a modern x64 system?

Viewed 93

This code for example:

int x = 75;
int *p = &x;

printf("%llx\n",p);

Writes a 64-bit number. What I'm asking is, what exactly is this number? Yes, it is an address.

But is it an absolute address in virtual memory where the value 75 is stored? Or is it possibly offset from some page marker, or an offset from the "start point" of the program's memory block?

If it matters, I'm asking about Windows 10, 64 bit, on a typical x64 intel chip.

2 Answers

Yes, it is the absolute address in your program's virtual address space.

It is not an offset.

In 16-bit Windows (which was common 30 years ago), a segmented memory model was used, in which pointers were segmented and consisted of a 16-bit segment pointer and a 16-bit offset (32 bits in total).

However, 32-bit and 64-bit Windows both use a flat memory model, which uses absolute addresses.

It is a virtual address, which is a virtual page number and an offset from the beginning of the page. The translation mechanism looks up in the page tables of the process to determine the corresponding physical page number and combines it with the offset to come up with the physical address.

Related