Section 12.4
Review Questions
The Principle of Locality
-
What keeps a computer from thrashing? Why does virtual memory work
as well as it does?
answer...
principle of locality
-
Define the principle of locality.
answer...
programs usually spend a large amount of time accessing just one small
region of their memory space before moving on to another section
-
What do we call a place in a program where a small chunk of code is
executed many, many times?
answer...
hot spot
-
Where are you more likely to see the principle of locality operating?
in code
in data
answer...
in code
-
Think of a time when the principle of locality could be seen in a region
of data memory.
answer...
when a certain variable, such as a sum, is repeatedly accessed in a loop
-
In the following chunk of pseudo-C code, circle the likely hot spot.
main() {
int xyz, def, w, x, i;
xyz = ....
def = ....
x = ....
while (xyz < 5) {
/* do something here... */
}
}
answer...
main() {
int xyz, def, w, x, i;
xyz = ....
def = ....
x = ....
+--------------------------------------+
| while (xyz < 5) { |
| /* do something here... */ |
| } |
+--------------------------------------+
}