I saw a piece of code that looked like this sample program:
#include <immintrin.h>
int main() {
int arr[1024];
for (int i = 0; i < 1024; i++) {
arr[i] = i;
}
// Declare a pointer to the first element of the array.
int *ptr = arr;
// Loop over the array, using _mm_prefetch to prefetch data into the CPU cache.
for (int i = 0; i < 1024; i++) {
_mm_prefetch((char *)ptr + 64, _MM_HINT_T0);
// Do something with the current element.
// ...
// Increment the pointer.
ptr++;
}
return 0;
}
Does this line in the program cause a heap buffer overflow towards the end of the loop?
_mm_prefetch((char *)ptr + 64, _MM_HINT_T0);
Or is it safe to prefetch memory outside the bounds of the array?