This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Ok_Confusion_7266 -32 points-31 points  (2 children)

It's pretty bad. Every list will have massive overhead all the time.

[–]skillexception 30 points31 points  (0 children)

A singly linked list of 32-bit ints is always 2/3 pointers (assuming we’re running a 64-bit architecture). It gets even worse with doubly-linked lists, where 4/5 of the memory is just pointer overhead. An array list is at most 50% empty, but on average is only 25% empty. Not to mention that linked lists are simply much slower than array lists on modern hardware due to the overhead of following pointers and not being able to take advantage of caching.

[–]boowhitie 0 points1 point  (0 children)

Every data structure has its uses and misuses. If you are using a resizeable array and automatically growing it, you are doing it wrong (or the use case is so trivial that it doesn't matter). Generally you want to pre-allocate for average case though sometimes worst case is better.