troublesome deque<bool>

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yuan

    troublesome deque<bool>

    hi,
    I do not know if this worth a cent.

    we know vector<boolis bad and we should use deque<bool>. However,
    this guy gives me some trouble, (pls correct me if I am wrong).
    In vector, the mem is guaranteed to be a continous block. however, for
    deque, NO!!

    So when we try to get an array out of a vector, we just set the
    pointer to be the &vec[0], done.
    For deque. get the address of the first elemen does not guarantee the
    following mem blocks belongs to the queue.

  • Juha Nieminen

    #2
    Re: troublesome deque&lt;bool&g t;

    Yuan wrote:
    we know vector<boolis bad and we should use deque<bool>.
    Why? The former will take considerably less memory than the latter.
    However,
    this guy gives me some trouble, (pls correct me if I am wrong).
    In vector, the mem is guaranteed to be a continous block. however, for
    deque, NO!!
    >
    So when we try to get an array out of a vector, we just set the
    pointer to be the &vec[0], done.
    For deque. get the address of the first elemen does not guarantee the
    following mem blocks belongs to the queue.
    You can't get a pointer to an element in a std::vector<boo lanyways,
    so you are out of luck.

    If you really want something that acts like a bool and where the
    elements are addressable, use std::vector<cha r>. It will take more
    memory than std::vector<boo l>, though (about 8 times as much).

    Comment

    • Pete Becker

      #3
      Re: troublesome deque&lt;bool&g t;

      On 2008-07-31 12:35:49 -0400, Yuan <yuanliu1@gmail .comsaid:
      >
      we know vector<boolis bad and we should use deque<bool>.
      We know that some people say this. We don't know that it's absolutely true.
      However,
      this guy gives me some trouble, (pls correct me if I am wrong).
      In vector, the mem is guaranteed to be a continous block. however, for
      deque, NO!!
      That's correct.
      >
      So when we try to get an array out of a vector, we just set the
      pointer to be the &vec[0], done.
      For deque. get the address of the first elemen does not guarantee the
      following mem blocks belongs to the queue.
      That's also correct.

      Different interfaces have different properties, and you should choose a
      container based on the properties that you need.

      --
      Pete
      Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
      Standard C++ Library Extensions: a Tutorial and Reference
      (www.petebecker.com/tr1book)

      Comment

      • Gennaro Prota

        #4
        Re: troublesome deque&lt;bool&g t;

        Yuan wrote:
        hi,
        I do not know if this worth a cent.
        >
        we know vector<boolis bad and we should use deque<bool>. However,
        this guy gives me some trouble, (pls correct me if I am wrong).
        In vector, the mem is guaranteed to be a continous block. however, for
        deque, NO!!
        >
        So when we try to get an array out of a vector, we just set the
        pointer to be the &vec[0], done.
        For deque. get the address of the first elemen does not guarantee the
        following mem blocks belongs to the queue.
        What are you trying to do which requires getting an array out? It
        could be that the operation you want is already provided by
        boost::dynamic_ bitset:

        <http://www.boost.org/libs/dynamic_bitset/>

        --
        Gennaro Prota | <https://sourceforge.net/projects/breeze/>
        Do you need expertise in C++? I'm available.

        Comment

        Working...