Section 12.4
Review Questions

The Principle of Locality

  1. What keeps a computer from thrashing? Why does virtual memory work as well as it does?
answer...
principle of locality
  1. 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
  1. What do we call a place in a program where a small chunk of code is executed many, many times?
answer...
hot spot
  1. Where are you more likely to see the principle of locality operating?
               in code
               
               in data
answer...
in code
  1. 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
  1. 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... */      |
  | }                                    |
  +--------------------------------------+
}