4 ms·
Ask HN: Why a Computer Need a “Memory”?
sry guys I am a totally newbie on computer science, lately I am learning the basic knowledge of computer science from a Youtube channel Crash Course, in their #6 episode, they talked about the hardware level of how a RAM built, I have a very hard time to get the idea why a computer needs a memory/RAM
For example, due to billions of transistors inside a CPU, say if we get a number 1110001010101 in somewhere of those transistors connected wires, why not just leave those wires as is (don't touch these wires), is this the same way as "store a value" as RAM does?
I am trying hard to visualize this hardware in my brain and why it is necessary to build so called "latch" or whatever, compare with just leave those wires (because we got enough wires inside)
Could anyone help on this topic? Any life example like play games, type words, watch videos or whatever, to prove a computer has to have a RAM to work?!
- PaulHoule 8y agoIf the memory was coded in the connections between the transistors, it would be a read-only memory, or a ROM.
- terrycody 8y agothanks for your reply, but this is not the answer I am looking, I want to know the reason why RAM is necessary for a computer, why not just leave those circuits untouched, because if a number is 10001011, those wires already got current, I don't need to store this number elsewhere, right?
- pwg 8y agoYou can't leave wires 'untouched' in an electrical system. Unless something continuously supplies energy to maintain the charge, the charges on those 'untouched' wires will simply fade away, and with it, your data. [1] The data is stored in the electrical charges on the wires, not in the actual wires, which appears to be one source of your confusion. Further, those wires will get reused on the next cycle for the next piece of data moving through, which means if you don't save the values represented by the current charge state of the wires, the data will be gone when the next cycle happens and new charges are forced onto the wires for the next piece of data. RAM (memory) is the place for holding onto those particular charges (which is what is storing the data) that were on the wires, until a later time when you want to go pick those pieces of data up again. [1] ignoring flash memory, which is a very specially designed "charge holder" that does not need the continuous energy supply to be able to maintain the charge states.
- AnimalMuppet 8y agoAmusing and somewhat related story: I was trying to (programmatically) tell the difference between two versions of a circuit board. At a certain address, version 1 had an 8-bit read-write register, and version 2 had a 16-bit read-write register. So I wrote a 16 bit value to that address, read it back... and read the correct value, even from the board that only had an 8-bit register there! What happened was, when I wrote the value, the bus driver chips drove all 16 bits of the bus to the levels specified by the data. Even if the data wasn't latched by the register, that bit of the data bus still had the voltage level corresponding to the data bit. When I read the value, the bus driver chips reversed direction, and wrote out what the voltage level on the data lines said. For the 8 bits that were not driven by the register, the voltage level they had was the voltage level that I just wrote to them (because every chip on those bits of the data bus was in a high impedance state, both for the read and for the write). So I was literally using the wires of the data bus as memory! I found that it could remember data for roughly two seconds this way. So, why do we need memory? Because we want the computer to remember for more than two seconds. And because we want it to remember more bits of data than we have transistors in the CPU chip. And because we want to use the transistors in the CPU chip for something else - for computing, not for memory.
- terrycody 8y agothank you for your story, I am too early to understand such a case lol, but I get the idea, which means, a wire can hold current a while, but not forever, yes this is clear, but why not just keep give the wires current flow? Then a "1" state stored! If we want to store another number, just use other wires! We have billions of transistors and bus wires right? Why a RAM is a must when we have near unlimited wires already ?
- AnimalMuppet 8y agoThe wires are a "data bus", which connects multiple things. You could think of it as a street, which has multiple houses on it. Sure, I could use the street to store my stuff in, but then other people can't use the street to get to their houses. It's better that I store my stuff in my house. This leaves the street free so that multiple people can use it to get to and from multiple houses.
- salawat 8y agoSo, you seem to be laboring under some drastic misunderstandings. Let me try to lay out an example that may make things clearer. I have a CPU. A CPU consists of a collection of general registers (data is generally read from and into here), a special set of registers containing metainformation about the state of the CPU, an arithmetic processing unit, and a clock circuit. This is a dirt simple CPU. Now. If you're using a Von Neumann based architecture, your CPU doesn't distinguish data from instructions. (Modern ones do, but ignore that for now.) An "instruction" consists of an op-code (basically a number), plus addresses indicating where input data is being read from, and where it's being written to. So a set of commands for this CPU might look like load $1 1 load $2 1 Add $1 $2 $3 Assuming we're "wired" into some input pin the CPU knows to listen to, we're running a rudimentary set of computations. We're sending in some number that the CPU recognizes as the beginning of a "load" command, it looks at the 8 bits or so following, and loads 00000001 into register $1. Done for that cycle. Next cycle, same deal, but in register $2. Next cycle, we send the contents of $1 and $2 to the adder, which outputs the result into $3. Easy right? Now. Let's do some REAL computation. Let's say I have a ridiculous amount of data to crunch. I have 30 8 bit registers for general use, and my 5 or 6 special registers, and my input pin. But I have 300000000000000 8 bit numbers that I want to add! I can make this work with just the CPU logic. I can do a bunch of serial computations, then record the results by hand, and re-input that result as an input to the next computation over and over again, But dear God, that's boring! Wouldn't it be great if somehow, I could stage all of my information ahead of time, and somehow have the processor look up that information to do it's calculating, with out me having to remember everything for it? The answer to that conundrum is Random Access Memory. It's a separation of concerns if you will. CPU's do computation. That's what they are for. Doing the stuff that might cause a state change. We don't want values sticking around in the processor that aren't changing if we can help it. Once something is done we want it out of the processor so we can accommodate the next state changes. In CS, we tend to have two main axes on which we measure the footprint of computation: CPU time, and space (memory footprint). If I have high space constraints, I can set up the CPU to handle all the state, but for every new computation, I have to reset everything back to basics, and still keep track of all my information. This quickly turns a simple one cycle operation into many cycles worth of operation and bookkeeping about where everything is. Or, If I have memory to write to, I can do my computation, write it out to somewhere that's memory managed, and let the magic Memory Management Unit feed me new data and instructions while also cleaning up results, and holding onto them elsewhere on the motherboard so I can use my full CPU die to do computations more quickly. Look at it like having a helper to get books for you at a library while you're sitting at home reading books and doing math problems. The library is RAM, you are the CPU, and your home is the CPU cache. Without your helper fetching books for you, you have to stop all the time, and take the books you're done with back, check out new ones, go home, and only then start doing math again. (You're not independently wealthy, or psychic, so absurdly big house, or magical access to all of the books by telekinesis is not allowed, sorry!) With your helper, you're doing math (yay!), and he/she's swapping out books to/from the library to keep you running smoothly. Try not to get caught up thinking about wires. Circuits have about as much to do with Computer Science as a scalpel does to Surgery. They're a tool. Nothing more. The important thing is to understand how all the pieces work together to create a functional whole. If you're still confused about why RAM is a thing, let me introduce you to https://en.m.wikipedia.org/wiki/ENIAC https://en.m.wikipedia.org/wiki/ENIAC A computer that, quite literally, was absolutely dependent on the people around it to play the role of "memory" since each computation required rewiring the damn thing. Ain't nobody got the patience for that anymore!