7 Replies - 430 Views - Last Post: 03 January 2013 - 01:37 PM Rate Topic: -----

#1 Mylo  Icon User is offline

  • Knows all, except most.

Reputation: 265
  • View blog
  • Posts: 747
  • Joined: 11-October 11

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?

#include <iostream>

using std::cout;
using std::endl;

int main()
{
	long long  myVar = 0;
	long long* myPointer = &myVar;

	cout << sizeof(myVar) << endl;     // 8
	cout << sizeof(myPointer) << endl; // 4

	cout << endl << endl;
	system("pause");
	return 0;
}

This post has been edited by Mylo: 03 January 2013 - 04:38 AM


Is This A Good Question/Topic? 0
  • +

Replies To: 4 byte pointer, 36 bits ram

#2 AKMafia001  Icon User is offline

  • </code.in.dream>

Reputation: 187
  • View blog
  • Posts: 624
  • Joined: 11-June 11

Re: 4 byte pointer, 36 bits ram

Posted 03 January 2013 - 03:20 AM

Pointers are 2 bytes on 16-bit systems, 4 on 32-bit, and 8 bytes on 64-bit systems...

I think that depends on the word size of a machine...
Was This Post Helpful? 1
  • +
  • -

#3 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2101
  • View blog
  • Posts: 3,204
  • Joined: 21-June 11

Re: 4 byte pointer, 36 bits ram

Posted 03 January 2013 - 07:09 AM

View PostMylo, on 03 January 2013 - 09:03 AM, said:

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.


This means that you're compiling your application as a 32-bit application.

Quote

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?


Yes, it would. 32-bit applications can't use more than 4 GB of RAM.
Was This Post Helpful? 1
  • +
  • -

#4 Mylo  Icon User is offline

  • Knows all, except most.

Reputation: 265
  • View blog
  • Posts: 747
  • Joined: 11-October 11

Re: 4 byte pointer, 36 bits ram

Posted 03 January 2013 - 07:26 AM

Thanks, I didn't know about that. Coming from a java background, C++ is just so much more complicated that I don't even know how to describe it :dead:
Was This Post Helpful? 0
  • +
  • -

#5 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2101
  • View blog
  • Posts: 3,204
  • Joined: 21-June 11

Re: 4 byte pointer, 36 bits ram

Posted 03 January 2013 - 07:32 AM

That's not specific to C++. If you're using a 32-bit JVM, you won't be able to use more than 4GB of memory in Java either.
Was This Post Helpful? 0
  • +
  • -

#6 Mylo  Icon User is offline

  • Knows all, except most.

Reputation: 265
  • View blog
  • Posts: 747
  • Joined: 11-October 11

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.
Was This Post Helpful? 0
  • +
  • -

#7 Aphex19  Icon User is offline

  • Born again Pastafarian.
  • member icon

Reputation: 614
  • View blog
  • Posts: 1,873
  • Joined: 02-August 09

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).
Was This Post Helpful? 1
  • +
  • -

#8 ishkabible  Icon User is offline

  • spelling expret
  • member icon




Reputation: 1622
  • View blog
  • Posts: 5,709
  • Joined: 03-August 09

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.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1