4 byte pointer, 36 bits ram

Posted 03 January 2013 - 01:03 AM

I was playing around with pointers and decided to see how big a pointer was. It seemed the pointer was 4 bytes in size, 32 bits. However, I have 8GB Ram, which comes to 2^36 bits. So wouldn't the pointer need at least be 36 bits to address all possible addresses?

Re: 4 byte pointer, 36 bits ram

Posted 03 January 2013 - 07:50 AM

Yeh, I was more referring to the fact that I actually have to now consider data type sizes for various platforms, and various compiler options, and knowing what each compiler supports (though I'll probably stick to VS) whereas that was close to non existent. But it will definitely improve my understanding of underlying concepts much further.

Re: 4 byte pointer, 36 bits ram

Posted 03 January 2013 - 08:29 AM

On a related note, your programs don't address memory physically, but virtually. This means that your programs can always see the full address space (either 2^32 or 2^64 bytes), and any address range within that space can be mapped to a physical address, which would indeed be limited to the amount of physical memory installed. If you want to know more, it's worth looking up the details of memory translation mechanism used in x86 (paging).

Re: 4 byte pointer, 36 bits ram

Posted 03 January 2013 - 01:37 PM

Quote

which would indeed be limited to the amount of physical memory installed

virtual memory, paging, and segfaults actually allow for pages to be stored on the hard drive temporarily. when the program attempts to use a page it's not assigned a segfault is triggered. the OS can first check to see if it stored that on page on the hard drive and swap out some pages then let the program go back to functioning normally. so actually, it's more limited to hard drive space then anything. this is also why windows guarantees 32-bit applications 2 GB of ram and 64-bit applications 2 TB of ram if there is available hard drive space.