Why is the size of RAM always in powers of 2? - hrasyid
======
Zergy
Individual sticks of memory always are powers of 2 because of how
multiplexers/demultiplexers work.

Basically there is a bit of circuit where every word of memory connects to a
bus. The Mux decides which one of the words is loaded on the bus. A series of
wires controls which gate is open.

If there is 1 wire there are two possibilities

0, 1

If there are 2 wires there are four possibilities

00, 01, 10, 11

If there are n wires there are n^2 possibilities.

Not using all the possible words for the number of wires. Example 3 words when
using 2 wires would cause there to be inputs that break the state machine the
instruction stack is interacting with and make developing for the chip very
complicated.

So the number of words that can be pulled is restricted by the capacity of the
Mux, which is driven by wires that are either off or on. This causes the
powers of 2.

[http://en.wikipedia.org/wiki/Memory_controller](http://en.wikipedia.org/wiki/Memory_controller)

[http://en.wikipedia.org/wiki/Multiplexer](http://en.wikipedia.org/wiki/Multiplexer)

------
gjmulhol
This is more a question of address space. If I have 1 bit, I can address 2
things (0, 1). If I have 2 bits, I can address 4 things (00, 01, 10, 11). With
2 bits, you can also address 3 things, but then you are wasting precious bits,
so it makes sense to try to fill up the address space available. Basically
everything inside a computer is based in binary and is therefore held to some
relationship with powers of 2. The way these addresses work in hardware is
basically to go into a massive decoder that lights up the right bit and makes
that bit available. If you don't use all your bits, you are basically wasting
available logic circuitry. In most DRAM (which is what you think of usually
talking about RAM), the capacitor is not the expensive part, the control
circuits are, so if you waste control circuits, you are not making the best
performance/cost proposition.

------
venomsnake
Total physical ram of the machine, ram modules or ram allocated by the
software?

The first is not always power of two - a machine with 6GB of ram works just
fine, the third - it is more convenient to allocate power of 2 sized blocks of
ram because this makes the allocation algorithms faster.

The second - not sure but I suppose it is more convenient - while there may
not be reasons while you cannot have 1023 Mbit block it makes no sense because
everything else is based on the power of 2 in computers anyway.

------
informatimago
Because when you add a wire to address bytes, you multiply by 2 the number of
addressable bytes.

