Many modern processors hash some of the address bits before using them as a cache index to avoid these problems.
To avoid them in code, it's often sufficient to round to convenient decimal numbers when allocating arrays, instead of powers-of-2. That is, allocate an array of 1000, instead of an array of 1024.