Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. ATL / WTL / STL
  4. should we prefer deque over vector

should we prefer deque over vector

Scheduled Pinned Locked Moved ATL / WTL / STL
c++performancecomgraphicsquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    yccheok
    wrote on last edited by
    #1

    after reading http://www.codeproject.com/vcpp/stl/vector\_vs\_deque.asp, i realize that deque has its own speed advantage over vector in all the aspect (except for memory deallocation). does it mean that we should prefer deque over vector? (in contrast with c++ standard, which recommence vector over deque) thanks!

    Z 1 Reply Last reply
    0
    • Y yccheok

      after reading http://www.codeproject.com/vcpp/stl/vector\_vs\_deque.asp, i realize that deque has its own speed advantage over vector in all the aspect (except for memory deallocation). does it mean that we should prefer deque over vector? (in contrast with c++ standard, which recommence vector over deque) thanks!

      Z Offline
      Z Offline
      Zac Howland
      wrote on last edited by
      #2

      That depends on what you are trying to do with the container. For example, if you are using vector to store char's (that is, use it instead of the string class), vector is a much better choice then deque since you can do things like the following:

      vector<char> charVec;
      // fill it somewhere
      cout << &charVec[0] << endl;
      

      Which would not work properly using a deque. If you are using the container as a pool of objects, then deque is a better choice.

      If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

      J 1 Reply Last reply
      0
      • Z Zac Howland

        That depends on what you are trying to do with the container. For example, if you are using vector to store char's (that is, use it instead of the string class), vector is a much better choice then deque since you can do things like the following:

        vector<char> charVec;
        // fill it somewhere
        cout << &charVec[0] << endl;
        

        Which would not work properly using a deque. If you are using the container as a pool of objects, then deque is a better choice.

        If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

        J Offline
        J Offline
        Jorgen Sigvardsson
        wrote on last edited by
        #3

        Zac Howland wrote:

        If you are using the container as a pool of objects, then deque is a better choice.

        Only if you need random access. list/queue is much better if random access/special ordering is important.

        -- Simulcast on Crazy People's Fillings

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups