ROM and RAM

RAM

Random Access Memory or RAM is a form of data storage that can be accessed randomly at any time, in any order and from any physical location., allowing quick access and manipulation.

RAM allows the computer to read data quickly to run applications. It allows reading and writing. It is non-volatile i.e. its contents are retained even when the device is powered off.

Static RAM vs. Dynamic RAM

Static RAM has a pair of transistors forcing each other on and off, so there are electric fields turning on channels to conduct and turn off the opposite transistor. This is a self-reinforcing state, so  it can go on forever.

In a dynamic RAM there is just a little bit of charge or not on the gate of a transistor.  This charge will leak away in milliseconds, as there is nothing actively maintaining it all the time.   So dynamic RAM need to have a refresh jolt every few milliseconds, where a pulse causes the read transistor to reinforce the charge level on its gate.

Dynamic memory takes about 1/4 of the parts per cells static memory, so it's about 1/4 the price and size and cost.

ROM

Read-only memory or ROM is also a form of data storage that can not be easily altered or reprogrammed. ROM stores the program required to initially boot the computer. It only allows reading. It is non-volatile i.e. its contents are retained even when the device is powered off.

The relation to stack and heap

RAM is actual physical memory for stack or heap.

The stack is a conceptual term, a certain range of the RAM that grows downwards.
When a function is called, arguments and return address are pushed onto the stack, they are popped out when the function is done.

The advantage of using the stack to store variables, is that memory is managed for you. You don't have to allocate memory by hand, or free it once you don't need it any more. What's more, because the CPU organizes stack memory so efficiently, reading from and writing to stack variables is very fast.

Unlike the stack, the heap does not have size restrictions on variable size (apart from the obvious physical limitations of your computer). Heap memory is slightly slower to be read from and written to, because one has to use pointers to access memory on the heap.

Unlike the stack, variables created on the heap are accessible by any function, anywhere in your program. Heap variables are essentially global in scope.



评论

此博客中的热门博文

Nu förbjuder Kina handel med elfenben

Fader av pingyins

Kineserna vill köpa Volvos kompetens