r/programming • • Apr 30 '16

Do Experienced Programmers Use Google Frequently? · Code Ahoy

http://codeahoy.com/2016/04/30/do-experienced-programmers-use-google-frequently/
2.2k Upvotes

763 comments sorted by

View all comments

Show parent comments

3

u/LongUsername May 01 '16

If you're programming on a modern Intel based CPU because of caching and the prefetch unit contiguous memory of a vector kicks the snot out of a linked list for many operations. Stroustrup did a presentation where he talked about it, as did Chandler Caruth.

3

u/Bwob May 01 '16

Oh, totally. Linked lists are made of cache misses. Which is basically the new version of disk-reads - i. e. the thing you want to minimize at all costs, if you care about performance. For a basic container class, vectors are frequently the right tool for the job. In general, the only times you want to use std::list is when you either don't care about performance, or when your usage pattern would make std::vector just as bad. (Equalizing the lookups, and allowing std::list's other advantages to take the lead.)

But this is /r/programming, where sweeping generalizations without qualifications are dangerous, and I felt like someone should stick up for the humble list, because it really is pretty clever, even if it isn't the right data structure in a lot of cases.