[SciPy-user] Naive Question about Data Representations

Brian Lewis brian.lewis17@gmail....
Fri Jun 20 23:47:07 CDT 2008

```On Fri, Jun 20, 2008 at 8:10 PM, David Warde-Farley <dwf@cs.toronto.edu>
wrote:

> On 20-Jun-08, at 9:48 PM, Brian Lewis wrote:
>
> > Sorry for my naivety.
> >
> > Can someone explain how it is possible to store more than 1 32-bit
> > integer on a 32-bit system?  I hope this questions makes my
> > confusion obvious.
>
> If by "32-bit system" you mean "32-bit processor/operating system",
> this refers to the number of bits in a memory address, and by
> extension that the system can deal with 2^32 distinct memory
> addresses / locations (4 GB on a 32-bit system, though you can't
> usually use a full 4GB of physical memory since lots of addresses are
> reserved for use by the system for things like I/O devices).
>

How do we go from 2^32 addresses to 4 GiB?  To make this jump, it seems we
associate each address with 1 B (8 bits).  Then 2^32 = 4 * 2^30 = 4
Gibi-addresses = 4 GibiBytes.  I understand that now, but if we associated
each address with something larger than 1 B, then the upper limit would be
larger.  So why does 1 address == 1 B?  It seems that having a 32-bit
processor/operating system, alone, is not the only constraint on why there
is a 4 GiB upper bound.

>
> A 32-bit integer will occupy 4 bytes of system memory (8 bits per
> byte), and any valid memory address will have to be such a 32-bit
> integer, but you could store much, much bigger numbers by just
> occupying more bytes of memory. For example, the long long type in C
> occupies 8 bytes = 64 bits.
>

Now I understand that we can store 2^32 Bytes / 4 Bytes = 2^30 integers
(upper bound).  Previously, I would have said:  "We have 2^32 locations,
which is just 32 bits....each integer requires 32 bits....so we should only
be able to store one integer".  Obviously, I know this not to be the case,
and the missing link was that each location corresponded to 1 B.   But why?
If we could associate each address with 2 Bytes, shouldn't the upper bound
for a 32-bit system be 8 GiB instead?

Relevance: I'm trying to understand the largest array (upper bounds) I can
make on my system, and I am not so familiar with these things.

>>> import struct; print struct.calcsize('P')
4

This means each pointer will take up 4 Bytes. So it is the size of an
integer, and I should be able to store 2^30, 32-bit integers (on a sunny
day).  Approx: 4 GiB of RAM.

Thanks again for your patience.   Please correct my mistakes and if
possible, shed light on why each address represents 1 B.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/scipy-user/attachments/20080620/000cb532/attachment.html
```