Starting from:

$24.99

CS1010S Tutorial 7 Solution

Memory and Cache
Note: The Coursemology tutorial training for computing topics usually consists of follow-up questions on the tutorial discussion. So, you should attempt the training only after trying out the tutorial questions and / or after attending the tutorial session.
1. If we call function f() in a loop:
for (int i = 0; i < 100; i++) { f();
}
What is the largest number of stack frame for function f() on the stack at any point in time?
2. Sketch the stack frames for the following code when the execution reaches the point α indicated. Pay attention to the relationship between the various variables i . Also, find out what is the value of i in main() at the end of execution.
void h(int& i) {
i = 33; // point α
}
void g(int* i) { *i = 22; h( *i );
}
void f(int i) { i = 11; g( &i );
}
int main() { int i = 0; f( i );
}
3. Suppose we access the memory block in the following sequence:
Blocks: 6, 1, 1, 7, 6, 2, 3, 0, 2, 4, 5, 3, 5, 4, 0, 7
1
Given a cache that can hold 4 memory blocks, i.e. the cache indices are 0, 1, 2 and 3, attempt the following:
(a) If the cache is fully associative and we replace the “oldest” block when needed, calculate the number of cache hits.
(b) If the main memory has an access speed of 50ns, and the cache takes only 5ns, what is the average access time for the above accesses?
(c) Repeat (a) and (b) by using a direct mapped cache.
4. (a) Given a main memory access speed of 100ns, and a cache of 10ns access speed, what is the cache hit rate to give an average access time of 20ns?
(b) Expand the same idea for 2 level caches:
i. Main memory has access speed of 100ns.
ii. Memory block is loaded into a L2 (level 2) cache of access speed 20ns.
iii. Memory block from L2 cache is loaded into L1 cache of access speed 10ns. Suppose L1 cache hit rate is 80% and L2 cache hit rate is 90%, what is the average access time of this setup?

More products