Previous: Casting Global Pointers Up: Global Pointers Next: Examples

Pitfalls

  1. A global pointer takes more memory than a local pointer, and it takes more time to dereference. Global pointers should be used to indicate that the data referenced is expensive to obtain.

  2. When creating objects whose member functions will be invoked through RPCs, keep in mind that each RPC creates a separate thread of control, and that concurrently executing RPCs on the same object might dangerously share mutable variables.

  3. Global pointers cannot be ordered, i.e. the relational operators >, <, <=, and >= cannot be used with global pointer operands. They may be compared for equality or inequality using the operators != and ==. An expression comparing a global pointer to 0 (NULL) will evaluate to true if the global pointer points to 0 in that processor object.
    
    {
      int *global gpint1;
      int *global gpint2;
      if (gpint1>gpint2) {...} // COMPILE-TIME ERROR
      if (gpint1==gpint2) {...} // OK
      if (gpint1==0) {...} // OK
    }
    

paolo@cs.caltech.edu