Tags: lec1

Q: What does a compiler do?
A: Convert high-level code (e.g., C++) to machine code that a CPU can directly understand.

Q: What is a cacheline, and why does it matter for performance?
A: Bringing data from RAM to the CPU is slow, so the CPU caches recent/hot data.  A cacheline (often ~64 bytes) is the unit at which data is brought into the cache.
This matters for performance because the cache is so much faster than RAM -- doing computations on two values in the same cache doesn't take much longer than doing one computation, for example.  To get good performance, you should think about how many cachelines will be brought to CPU cache when your program runs, not just how many values you touch.

Q: What is a garbage collector, and does C++ have one?
A: A garbage collector identifies objects that are still in memory, but not accessible anymore.  For example, perhaps you previously had one variable referring to an object, but then assigned that variable a different value -- the object is still in memory, but it is garbage, because no code could possible use that value anymore.
C++ does not have a garbage collector, so you need to write code to free up memory when appropriate.

Q: What are pros/cons of having a garbage collector?
A: Pro: easier to program
Con: less efficient (unused memory may not be reclaimed immediately, and garbage collection is often performed by a background process that pauses normal execution, perhaps for many seconds at large scale)

Q: What is an address space for a process?
A: Basically a big array of bytes that the process can use to keep data in memory.  An address is an index into the array.  Some of the bytes may be in valid (that is, "mapped") ranges, and some that are not valid (that is, "unmapped").

Q: If you have items[idx] = 3 where idx is too big, most languages will throw an exception.  What are a few things C++ might do?
A: 1. modify unused memory (the update will be invisible)
2. modify a different data structure that is not items (memory will be corrupted and this will show up in strange ways later)
3. segfault if the memory it tries to touch is not mapped in the address space (the program will crash)

Q: Which ones are object-oriented programming languages?
Python, Java, C, C++
A: All these are object oriented (except C).