Week 2 Flashcards
Describe the memory layout of a C program?
Command argc. and env. vars |
Stack Segment | Local or automatic variables, each function gets a frame. (grows high to low)
Heap Segment | Dynamically allocated variables.
Data Segments | Two data segments contain initialized/uninitialized global and static variables.
Text/Code Segment | Program/executable instructions.
What is the difference between Pass-by-Value and Pass-by-Reference?
Pass-by-Value: Function creates local copy of variable (data object)
Pass-by-Reference: Function gets copy of address of variable (pointer)
Why are memory hierarchies implemented?
To emulate a “large, fast and cheap” memory.
Explain memory hierarchy?
Keeps data that processor requires now, with extra data, close to the processor in fast memory.
How do you interface with a memory hierarchy?
Expose Hierarchy: CPU can access any level directly.
Hide Hierarchy: Single memory with single address space, hardware takes responsibility of storing data in fast or slow memory, depending on usage patterns.
What is Locality of Reference?
The tendency of a processor to access the same set of memory locations repetitively over a short period of time.
Describe Temporal and Spatial Locality?
Temporal: Reuse of specific data and resources in a small time duration.
Spatial: Use of data elements within close storage locations.
How does a computer try to increase Locality of Reference?
Keeps most used data in SRAM (cache).
Refers to large DRAM for data not in cache.
Swap space (disk) only used when data cannot fit in DRAM.
How does the C compiler store 2D arrays?
In a row-major order, e.g. all elements of row 0, then 1….