Next: SIn_Array Example, Previous: SIn Array Object, Up: SIn Array Object
Many extensions will need to collect data for each (or some) static instructions. For example, an extension might need to individually compute the hit ratio for each load instruction so that if can find the most troublesome loads. Suppose a structure Load_Info is to be used for collecting the data and that Load_Info is large (because it collects more than just cache miss data, say). The code below shows a wasteful way to allocate such an array.
Load_Info *load_info_array = new Load_Info[num_all_instructions]; Load_Info *li = load_info_array[din->pc];
It is wasteful because enough Load_Info objects for all instructions are allocated even though they are only needed for load instructions.
Using the SIn_Array
object structures would only be allocated
when needed. Here is how the code above would be written:
SIn_Array<Load_Info> load_info_array; Load_Info *li = load_info_array[din];
In the code above only one Load_Info
object is created (because
only one was accessed). As an added benefit, load_info_array
can be indexed by an instruction index (din->pc
), a DIn
pointer or a SIn
pointer. There is also an iteration function
for easily examining the contents.