I understand that 32 bit programs are limited to 4gb of ram because their pointers are 32bit. Buy why are their pointers 32bit long even in a 64bit system why can't the pointers store memory addresses in a long datatype for example instead of unsigned int?

  • Why? Because that’s simple how the AMD 64-bit x86 extension works – Ramhound Dec 4 '17 at 1:49
  • 1
    @Ramhound oh so that's just how it works? OK cool thanks – code511788465541441 Dec 4 '17 at 1:50
  • In order to explain the reason 32-bit registers are used even when long mode is enabled would require an answer that explains the entire 64-bit architecture. Which has been documented before in numerous books. – Ramhound Dec 4 '17 at 1:57

You have a few questions here:

  1. Why aren't C pointers longs: because a long is actually two memory locations more or less glued together. Now your pointer is really two pointers which, in addition to throwing away more of your precious working memory, is more complex to deal with. This is more or less the way that support for more memory was added to old 8 and 16 bit computers. This is used in some special cases, like on old 32 bit versions of Windows Server.

  2. Why aren't 32 bit applications on 64 bit systems "promoted" to 64 bit: because while it might work on small, simple programs it could very well break custom data structures and various hacks the programmer put in place. It's technically doable to take a binary and 'recompile' it for 64 bit but the odds of it working perfectly are pretty low for various reasons. We don't really do that because the application was certainly designed to max out at 4gb so the programmer at the time should've prepared for that.

This is a really complicated architecture issue and I've had to simplify a ton of things. Best to leave this at "because it works that way"

  • Thanks for explaining that long is actually two memory locations. I'm still don't understand why we can't reference more memory spaces from a 32 bit programs using a long. For example if we want to reference address #(2^32)+10 why can't we have a long that stores that number then we can reference that location and read or write to it – code511788465541441 Dec 4 '17 at 2:10
  • 2
    The thing is we can, and we have done this before using some fancy techniques. We don't do this often in 32 bit except in special cases (like servers) because programs must be explicitly designed to utilize these special long pointers (ie server VM programs). This cannot be automatically forced upon applications because it'll most likely cause fires everywhere. – Allison Dec 4 '17 at 2:12
  • @code511788465541441: A long long doesn't fit in the CPU structures used for accessing memory. – Ignacio Vazquez-Abrams Dec 4 '17 at 2:13
  • @IgnacioVazquez-Abrams not natively, but you can do some weird bootstrapping to make it work. PAE is what this is commonly known as and it's part of pretty much all late 32 bit CPUs. See serverfault.com/a/34957/417964 – Allison Dec 4 '17 at 2:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.