As far as I know, the size of the pointer on 32-bit systems is usually 4 bytes, and on 64-bit systems, 8 bytes. But as far as I know not all the bits are used to store the address. If so, is it safe to use free bits for other purposes? If so, how, and how many free bits are available on 32-bit and 64-bit systems in pointer memory space?
-
The only bits I know are safe to use are when you know your type is aligned on for example 8 bytes, then theres 3 bits that are guaranteed to be 0 so you can use those. (I think this is llvm's implementation of it: http://llvm.org/doxygen/PointerIntPair_8h_source.html) – Borgleader Jul 16 '18 at 12:35
-
You should stay on the byte boundary. – Ron Jul 16 '18 at 12:37
2 Answers
At the time of writing the current 64 bit Intel chips use 48 bit pointers internally.
Every C++ compiler I've come across abstracts this 48 bit pointer to a 64 bit pointer with the most significant 16 bits set to zero.
But the behaviour on using any of the free bits is undefined.
Towards the end of 32 bit chips being the norm, it was possible to have 4GB of physical memory, let alone virtual memory. All 32 bits were used for a pointer.

- 231,907
- 34
- 361
- 483
-
-
4@JoeJoe You need all 32 bits to address every byte of ram you could have, it's only ~4GB. 48 bits gets you 256TB of addressable memory. – NathanOliver Jul 16 '18 at 12:47
-
-
@JoeJoe Most likely, or older 32 bit systems. IIRC some before XP, and maybe even with XP, that max memory windows would handle was 2GB. – NathanOliver Jul 16 '18 at 12:54
-
@JoeJoe Here is a real-ish example of this useage: https://youtu.be/vElZc6zSIXM?t=1329 – NathanOliver Jul 16 '18 at 13:03
-
@NathanOliver I've been looking for that talk! I wanted to link to it in my comment but couldn't find it. – Borgleader Jul 16 '18 at 13:05
-
On intel the pointer value must be sign extended. But negative addresses are only accessible to privilegied processes. – Oliv Jul 16 '18 at 13:26
It is not portable to use any bits in a pointer value for a different purpose.
You can look at the documentation for your platform to see if it guarantees that any particular bits in a pointer value are available for use. It is likely that even if they are not directly involved in addressing, they are reserved for use by the platform.

- 52,200
- 2
- 44
- 75