3 ms·
Pointers are not slow because they are pointers. Pointers are slow because (usually) they point to random locations in memory, incurring cache misses. Pointers
by moth-fuzz 5y ago
Pointers are not slow because they are pointers. Pointers are slow because (usually) they point to random locations in memory, incurring cache misses. Pointers that point to contiguous memory can be just as fast as that same memory being accessed via an array directly, as long as the data stays contiguous.
- habibur 5y ago> as long as the data stays contiguous The data will stay contiguous as long as it's constant/read only. But as soon as you start to use it and change it for doing some real work, it will get scattered.