memory in c
memory in c
Primary Memory
• It is also known as the main memory of the computer system. It is used to store
data and programs or instructions during computer operations. It uses
semiconductor technology and hence is commonly called semiconductor memory.
Primary memory is of two types:
• RAM (Random Access Memory)
• ROM (Read Only Memory)
RAM (Random Access Memory):
• The most common type of memory is called random access memory (RAM). As
a result, the term memory is typically used to mean RAM..
•This is a circuit which have its separate space or slot in motherboard. RAM holds
data and program instructions while the CPU works with them.
• When a program is launched, it is loaded into and run from memory. As the
program needs data, it is loaded into memory for fast access.
• As new data is entered into the computer, it is also stored in memory but only
temporarily.
• RAM is volatile, meaning that it loses its contents when the computer is shut off
or if there is a
power failure. Therefore, RAM needs a constant supply of power to hold its data..
RAM is of two types:
• D RAM (Dynamic RAM): D RAM uses capacitors and transistors and stores the
data as a charge on the capacitors.They contain thousands of memory cells. • Each
bit of data is stored in a single capacitor, and the charge can leak away over time.•
Needs to be refreshed thousands of times per second. It needs refreshing of charge
on the capacitor after a few milliseconds. • DRAM works slower than SRAM.
Mostly used because it is much
cheaper than SRAM and requires less space.
• Eg DDR1,DDR2,DDR3,etc..
ROM(Read-Only Memory)
• Unlike RAM, Read-only memory (ROM) permanently stores its data, even when
the computer is shut off.
• ROM is called nonvolatile memory because it never loses its contents.
• Whenever the computer's power is turned on, it checks ROM for directions that
help it start up, and for information about its hardware devices.
• ROM is used to store information that is used to operate the system. As its name
refers to read-only memory, we can only read the programs and data that is stored
on it.
• The information stored in the ROM in binary format. It is also known as
permanent memory.
ROM is used to store permanent or semi-permanent data, such as firmware or
software that doesn't change often.
ROM is of four types:
• PROM (Programmable Read Only Memory): This read-only memory is
modifiable once by the
user. The user purchases a blank PROM and uses a PROM program to put the
required contents into the PROM. Its content can’t be erased once written.
• EPROM (Erasable Programmable Read Only Memory): EPROM is an extension
to PROM
where you can erase the content of ROM by exposing it to Ultraviolet rays for
nearly 40 minutes.Often used in applications where data might need to be updated,
but not very frequently (e.g., in embedded systems or early computer BIOS).
• EEPROM (Electrically Erasable Programmable Read Only Memory): Here the
written
contents can be erased electrically. You can delete and reprogramme EEPROM up
to 10,000 times.
• Erasing and programming take very little time, i.e., nearly 4 -10
ms(milliseconds). Any area in an EEPROM can be wiped and programmed
selectively.It can be rewritten multiple times, but
not as quickly as regular RAM.
• Used in situations where small amounts of data need to be stored or updated, like
in microcontrollers, configuration settings, and some types of firmware.
• MROM(Masked ROM): Hard-wired devices with a pre-programmed collection
of data or
instructions were the first ROMs. Masked ROMs are a type of low-cost ROM that
works in this
way.
Secondary Memory
Registers: Registers are small, high-speed memory units located in the CPU. They
are used to store the most frequently used data and instructions. Registers have the
fastest access time and the smallest storage capacity, typically ranging from 16 to
64 bits.
Cache Memory: A small, fast memory located between the CPU and main memory
(RAM) that stores frequently accessed data or instructions.
Main Memory: Random Access Memory (RAM) is the primary memory used by
the computer to store data and instructions that are currently in use. Provides fast,
temporary storage for running programs and data.
Magnetic Disks: A magnetic disk is a secondary storage device that uses rotating
platters coated with magnetic material to store data. It provides long-term storage
for data.
Optical Disk (CD, DVD, Blu-ray): Optical disks use laser technology to read and
write data on the surface of discs like CDs, DVDs, and Blu-ray discs. Used for
media storage, software distribution, and data backup.
Magnetic Tape: Magnetic tape is a sequential storage medium that stores data on a
long strip of plastic tape coated with magnetic material.Used primarily for backup
and archival purposes due to its large storage capacity.
Registers
• CPU registers are small, high-speed storage units inside the CPU that allow quick
access to data, instructions, and memory addresses during program execution.
They are faster than other memory types, like RAM, and play a crucial role in
enhancing the performance of the computer by providing immediate access to
necessary information.
Important Registers in a CPU:
Program Counter (PC):Stores the address of the next instruction to be executed. It
helps the CPU know where to fetch the next instruction from in memory.
Accumulator Register (A):Often used in arithmetic and logic operations. For
example, in a CPU, when adding two numbers, the result is typically stored in the
accumulator.
Instruction Register (IR):Holds the instruction that is currently being executed.
After fetching an instruction from memory, it is loaded into the IR for decoding
and execution
Stack Pointer (SP):Points to the current top of the stack. The stack is used for
function calls, local variables, and returning to previous states in the program.
Memory Address Register (MAR):Holds the address in memory where data is to
be fetched or written.Used to specify the memory location during read or write
operations.
Memory Data Register (MDR):Holds the data that is being transferred to or
from memory.
Cache Memory
• Extremely fast memory type that is placed between main memory and the CPU.
• Holds frequently requested data and instructions, ensuring that they are
immediately available to the CPU when needed.
• Whenever the CPU needs to access memory for a data/ instruction , it first checks
the cache memory. If the data is not found in cache
memory, then the CPU checks into the main memory.
• Costlier than main memory or disk memory but more economical than CPU
registers.
• Used to speed up processing and synchronize with the high-speed CPU.
Cache memory is divided into different levels based on proximity to the CPU and
size.
L1 Cache: The smallest and fastest cache, located directly inside the CPU, stores
the most frequently used data and instructions
L2 Cache: Larger and slower than L1, it stores data that isn't in the L1 cache but is
still needed frequently, located either inside or near the CPU.
L3 Cache: The largest and slowest cache, shared between multiple CPU cores,
provides additional storage for data that supports multi-core processing.
Characteristics of Memory Hierarchy
• Capacity: It is the global volume of information the memory can store. As we
move from top to bottom in the Hierarchy, the capacity increases.
• Access Time: It is the time interval between the read/write request and the
availability of the data.As we move from top to bottom in the Hierarchy, the access
time increases.
• Performance: One of the most significant ways to increase system performance is
minimizing how far down the memory hierarchy one has to go to manipulate data.
• Cost Per Bit: As we move from bottom to top in the Hierarchy, the cost per bit
increases i.e. Internal Memory is costlier than External Memory.