Understanding how cache works
Hi,
I have a basic question regarding how cache memory works.
Let say I have a vector that does not fit into my cach memory (too large.) and this vector contains random numbers (ints) that are sampled from a set which is of the size equal to the size of my vector.
Now I traverse my vector from 0 towards the end and each time i come accross a value I insert it into another vector on a position defined by the value itself.
Code:
vector<int> vec1(n); // full of rand numbers from 0 to n
vector<int> vec2(n); // empty
for(int i =0; i < n ; i++){
vec2[vec1[i]] = vec1[i];
}
Is this a cach friendly code? Does vec2 fill the cach each time it is called upon ?? I understand that when I iterate tzhrough vec1 i fill L1 but if i call another vector as i do in the above example does it clear my L1 and fills it with vec2 and so on or not?? what happenes? what is the underlying mechanics??
thnx
b