Computer Science Crash Course - Session 1
Computer Science Crash Course - Session 1
Computer Science Crash Course - Session 1
● Small but fast memory space located on the CPU to reduce read/write time from RAM
○ Faster than RAM, slower than registers
● 1 CPU may have multiple caches, each divided into lines
○ When cache miss happens, CPU will load the memory address, along with adjacent addresses in the same
line, into the cache line
→ Accessing adjacent memory addresses is beneficial for performance - Spatial Locality!
External storage - Mechanical vs Flash
Let's see the Game Boy in action!
Stack versus Heap
Item Stack Memory Heap Memory
Allocation/read/write speed Fast (simple procedure, cache-friendly) Slower (complex management, not cache-friendly)
Access Only to the thread which owns the stack All thread can access the heap
● Instruction pipelining
○ Instruction life cycle
■ Fetching the instruction from memory
■ Decoding the instruction
■ Executing
■ Memory accessing
■ Writing back
○ The same CPU core can execute different stages of different
instructions at the same time
→ Instruction-level parallelism!
How did computers improve over time?
● Speculative execution
○ Instructions are loaded and executed before the task is needed
○ Reduce the overhead at branch conditions
○ If the task is indeed not needed, changes are reverted/not committed
● Can be an attack vector for cyber criminal!
○ Side-channel attack - faster execution of instructions in the CPU's cache can be measured and indicate
specific conditions of data in memory → in-memory secret can be discovered!
○ Example: Spectre and Meltdown
How did computers improve over time?
● Improvement in RAM
○ Higher speed
○ Higher capacity
○ Multi-channel RAM
New computational units