Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The funny thing is, in a language like Zig where memory allocation is explicit, linked lists are way more popular, just like they were in C. What happens IRL depends on your environment. :)


Linked lists are not popular in zig though. There are pages and pages of discussions about how linked lists are almost universally slower than an array. Zig devs are borderline obsessive about cache efficiency.


Linked lists are slower if you iterate over them fully, however, that's not the only use case. Removing something, while keeping things in order. That's an O(n) operation on vectors, unless you have some kind of fancy segmented structure. Adding might need an allocation, even ignoring the option of failure, that's an unpredictable delay. On the other hand, linked list insert is O(1) and has no allocation involved. These are the properties people use linked lists for.


Even if we set aside the performance consideration of using a linked list, if you have to re-implement a linked list, there's something wrong with your language ecosystem.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: