Friday, August 15, 2008

How computers remember things


A binary computer records, calculates and manipulates by using little switches - microscopic transistors - almost like a child would use it's fingers to remember numbers or do sums.

These transistors are so small you could fit a few million in a square centimeter - they are the computer in the computer:

Each one of the little darling things have 3 legs, called the collector, the emitter and base. In essence a transistor is an electronic switch: apply current to one of the legs and it "opens a switch" between the other two two legs - allowing current to flow.

Dandy!

Remove the current to the collector leg and the switch closes.

Cool!

Transistors are used to store all the 1's and 0's that make up all data and all instructions in a computer. These little tykes are FAST. Very, very fast. Measure the time it would take to open or close the switch and you are talking a few NANO (millionth) seconds.

A typical computer you'd buy today would have at least 1 Gb of these little machines. One Giga byte is 1024 megabytes, which is one 1024 kilobytes which is 1024 bytes which is 8 bits. Total number of transistors = 8 589 934 592. Yup, 8.5 BILLION.

The transistors are mounted in chips called "RAM" - Random Access Memory. (If you want to know why it's called RAM let me know with a comment in the blog). Now, let's put them to use:

Let's imagine that a computer nerd you know is writing a newsletter. (We all know one, right?). He would sit there furiously banging the keyboard for hours on end, spewing brilliant insight and stupendous wit. Assisting him in this noble task is a keyboard and a computer. When he presses a key, his keyboard and his computer discuss things and store that letter in the computer's memory.

"Storing" the letter means the computer will switch on (or off) a few transistors in its RAM to "remember" the key pressed. (To be precise, 8 transistors is switched on or off for every letter)

He types hundreds of words. Then he re-types hundreds of other words, fixes spelling errors and ignores grammar rules.

Before lunch his masterpiece is done.

Just about then Escom feels the urge to shed some load, and promptly cuts the power to our nerd's computer. Poof! No more power.

Expletives are used.

What happed to the RAM in the computer?

It's memory...became...blank.

The newsletter (all the key presses) are stored in memory right? Memory consists of transistors, right? A transistor needs power in order to maintain an "on" state, right?

Oh fudge.

No power = blank memory.

"Wait a second", I hear you think in your head, "didn't he say computers never forget?".

Indeed I did. Here is the second part of the story - long term storage or "hard disks".

RAM ("memory") has tree big problems: a) it does not maintain state unless it has power and b) it is limited in terms of how many transistors you can put in a computer and c) it is expensive.

A hard disk works like this: It consists of several "platters" (a very thin circular plate) coated with a magnetic layer. At a microscopic distance above each plate a magnetic read/write "head" is mounted on a moving arm. The plates spin around a spindle (at about 3500 rpm) and the arm positions the head above the platters.

The job of the head is to magnetize and de-magnetize particles on the disk. Where a transistor (bit) is switched on, the head leaves a magnetic charge on the platter. Where the transistor is off, the head erases (removes) the charge.

When the power goes off....

Nothing. The magnetic charge will stay there for several years. Decades even.

Problem is solved: before you remove power to a computer, write the state of it's memory to it's hard disk for long term storage.

Even better: with a hard disk a computer can process more data than the size of it's memory - by "paging" data to and from the disk. In other words, it can read a 1 Gb "page" from the disk, process it, write the result to the hard disk an get the next page.

So why use RAM at all if disks are so cool?

The biggest issue is the access time on a hard disk: the time it takes to store and retrieve information is measured in milliseconds, or thousandths of a second. This makes hard disks several thousand times slower than RAM.

Given that we are using computers that can perform several billion operations per second, we need fast memory to keep the processor "fed" with data to process, so the operating system quietly and invisibly funnel data to and from disk / memory to keep things running as smoothly as possible. (This process is called "virtual memory" and uses the "paging" file on windows systems)

More memory in your computer means less disk read/writes which means faster overall performance.

The BIG downside of a hard disk (other than slow access)? In one word: Friction.

A hard disk consist of moving parts and will, as will all moving things on earth, one day STOP moving. It is a mechanical device that will break, as surely as each of us will someday too, stop moving.

This is why they invented backups and wills. ;-)

That's a backup for the disk drive and will for yourself of course.

Although, come to think about it, the absence of one could force to the creation of the other...

Computers never forget? Pfft. Sure they do. All the time.

3 comments: Read or post...:

Anonymous said...

Hi Waldo

Like your writing style and the way you make complicated things simple to understand. Keep it going.

Thomas (http://www.psychsoma.co.za)

Anonymous said...

Yes, OK - why is RAM, RAM?

Waldo Louw said...

I thought you'd never ask. ;-)

RAM is "Random Access Memory", ie "memory" as we know it today.

In the "old" days (20 or so years ago) computers used Sequential Access Memory - magnetic tapes or card readers. The computer had to start reading / writing at one end and continue to the last bit - one could not "move" around.

This type of memory is not used incomputers any more...except for a few people who use tapes to backup their systems.

The other kind of memory is ROM. This is "Read Only Memory" and is typically used in devices (eg keyboards, screen cards, etc). As the name implies data is written to it once (at the factory) and it never changes...upside is that it does not need electricity to "remeber"...kind of a permanent burn-in. It is usefull load programs into devices that will never need to change...like programming a printer how to eject a page, or a microwave how to spin it's platter.

For more on the subject, see WikiPedia:
http://en.wikipedia.org/wiki/Random_access_memory