1

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?

Joe Joe
  • 121
  • 6
  • 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 Answers2

8

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.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
3

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.

Caleth
  • 52,200
  • 2
  • 44
  • 75