Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the benefit of larger pointers on 64-bit systems?

I am trying to understand 64-bit compiling, so I did a little test in C++ Builder:

  int i = 12345;
  ShowMessage(i);
  int *pi = &i;
  ShowMessage(sizeof(pi));


  Largeint li = 9223372036854775807;
  ShowMessage(li);
  Largeint *pli = &li;
  ShowMessage(sizeof(pli));

When I compile this program as 64 bit, the size of the pointer increases to 8 bytes (64 bits).

What is the advantage of the increased pointer size?

like image 485
İsmail Kocacan Avatar asked Nov 04 '15 08:11

İsmail Kocacan


Video Answer


2 Answers

A pointer can hold the address of a single byte in memory. Based on its size you can calculate the maximum number of different values a given pointer can store.

With a pointer of 4 bytes (32 bits) you are limited to address only 4GB of memory, since:

2^32 = 4294967296

On the other hand, a 8 bytes (64 bit) pointer is able to address a much wider range of 17179869184GB theoretically:

2^64 = 18446744073709551616

This are 16EB (exabytes).

In practice, it is much less than that, because of limitations on most processors and the physical size of the memory etc.

You can read more on this topic here:
https://en.wikipedia.org/wiki/64-bit_computing#Limitations_of_practical_processors

like image 111
oo_miguel Avatar answered Sep 22 '22 07:09

oo_miguel


Unless you want to go back to the old days of memory paging (remember those 16 bit Z80 machines in the 1980s with 128k RAM), or early DOS expanded memory, then you need more than a 32 bit pointer to address all the available memory on a modern machine.

A 64 bit pointer is a natural (though not a necessary) choice for a 64 bit architecture.

Note that pointers of different types do not have to be the same size: sizeof(double*) does not necessarily have to be the same as sizeof(int*), for example.

like image 41
Bathsheba Avatar answered Sep 22 '22 07:09

Bathsheba