Graphics Reference
In-Depth Information
[0]
Hot fields
Cold fields
[0]
[1]
[1]
[2]
[2]
Figure 13.2 Given an array of three structure instances (with frequently accessed “hot” fields
in light gray), hot/cold splitting rearranges the data so that cold fields are stored separately
and the array structure only contains hot fields (plus a link to where the cold fields are located).
for(inti=0;i<1000; i++)
if (elem[i].value > elem[index].value) index = i;
// Increment the count field of that element
elem[index].count++;
If this search is the predominant operation on this array of structures, it would
make sense to split the structure S into a hot part ( S1 ) and a cold part ( S2 ) and rewrite
the code as follows:
// Hot fields of S
struct S1 {
int32 value;
} elem1[1000];
// Cold fields of S
struct S2 {
int32 count;
...
} elem2[1000];
// Find the index of the element with largest value
int index = 0;
for(inti=0;i<1000; i++)
if (elem1[i].value > elem1[index].value) index = i;
 
Search WWH ::




Custom Search