Either directly or indirectly, accessing and manipulating data requires an evaluation system. When your program (and TotalView, of course) accesses data, it must determine where this data resides. The simplest data lookups involve two operations: looking up an address in your program’s symbol table and interpreting the information located at this address based on a variable’s datatype. For simple variables such as an integer or a floating point number, this is all pretty straightforward.
Looking up array data is slightly more complicated. For example, if the program wants my_var[9]—this chapter will most often use C and C++ notation rather than Fortran—it looks up the array’s starting address, then applies an offset to locate the array’s 10th element. In this case, if each array element uses 32 bits, my_var[9] is located 9 times 32 bits away.
In a similar fashion, your program obtains information about variables stored in structures and arrays of structures.
Structures complicate matters slightly. For example ptr->my_var requires three operations: extract the data contained within address of the my_var variable, use this information to access the data at the address being pointed to, then display the data according to the variable’s datatype.
Accessing an array element such as my_var[9] where the array index is an integer constant is rare in most programs. In most cases, your program uses variables or expressions as array indices; for example, my_var[cntr] or my_var[cntr+3]. In the later case, TotalView must determine the value of cntr+3 before it can access an array element.
Using variables and expressions as array indices are common. However, the array index can be (and often is) an integer returned by a function. For example:
my_var[access_func(first_var, second_var)+2]
In this example, a function with two arguments returns a value. That returned value is incremented by two, and the resulting value becomes the array index. Here is an illustration showing TotalView accessing the my_var array in the four ways discussed in this section:
Figure 186 – Expression List Window: Accessing Array Elements
In Fortran and C, access to data is usually through variables with some sort of simple evaluation or a function. Access to variable information can be the same in C++ as it is in these languages. However, accessing private variables within a class almost always uses a method. For example:
myDataStructureList.get_current_place()
TotalView built-in expression evaluation system is able to understand your class inheritance structure in addition to following C++ rules for method invocation and polymorphism. (This is discussed in "Using C++".)