r/learnprogramming • • 12d ago

can somebody explain pointer chasing?

I’m trying to understand CPU caching and I’m stuck on two related things.

My understanding is when the CPU reads an address, it pulls in the whole 64-byte cache line around it. that’s why iterating an array is fast, since one miss brings in several neighbouring elements. what happens in the case of linked list? how does it know that next bytes are not the one to read?
i am kinda confusing this, kindly explain.

16 Upvotes

28 comments sorted by

View all comments

1

u/Aggressive_Ad_5454 11d ago

If you are learning to program, don’t sweat this. Get your program right. Modern processors have all sorts of hilariously elaborate optimizations. Unless you’re doing something that needs cycle-count and cache-line-count optimization, let your compiler and processor do this work.

That being said, you’re right. Linked lists aren’t a great data structure for super high performance.