Why would I prefer using vector to deque

前端 未结 10 1717
陌清茗
陌清茗 2020-11-29 17:10

Since

  1. they are both contiguous memory containers;
  2. feature wise, deque has almost everything vector has but more, since it is more efficient to insert
10条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 18:06

    You woudn't prefer vector to deque acording to these test results (with source).

    Of course, you should test in your app/environment, but in summary:

    • push_back is basically the same for all
    • insert, erase in deque are much faster than list and marginally faster than vector

    Some more musings, and a note to consider circular_buffer.

提交回复
热议问题