Please see the following link, page 22 onwards:
the above link suggests if I have an object containing vectors/arrays like this:
class MyClass{
public:
double a[1000];
double b[1000];
};
and the code below iterates through a vector of MyClass and performs some Math on std::vector b:
std::vector<MyClass> y;
y.populateVector();
for(auto x : y){
//Iterate though x.b and do some math;
for(int i=0; i<1000; i++){
std::cout << x.b[i] << std::endl;
}
}
when we retrieve each MyClass object all the data from both of the arrays will be loaded in to the cache line. Is this true? I didnt think the data a
would be loaded in to the cache line because the address for accessing b
would be calculated and loaded.
I am trying to get an idea how much of a MyClass object is loaded in to the cache in comparison to the useful data required for processing?
I can understand if the very first b
element shared the same cache line as the very last a
elementbut I didnt think the whole object would get loaded in to the L2/L3 cache just to process one part of the object?