When should I use a List vs a LinkedList

后端 未结 15 2266
挽巷
挽巷 2020-11-22 14:50

When is it better to use a List vs a LinkedList?

15条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 15:23

    So many average answers here...

    Some linked list implementations use underlying blocks of pre allocated nodes. If they don't do this than constant time / linear time is less relevant as memory performance will be poor and cache performance even worse.

    Use linked lists when

    1) You want thread safety. You can build better thread safe algos. Locking costs will dominate a concurrent style list.

    2) If you have a large queue like structures and want to remove or add anywhere but the end all the time . >100K lists exists but are not that common.

提交回复
热议问题