troublesome deque<bool>

Y

Yuan

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

we know vector<bool> is 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.
 
J

Juha Nieminen

Yuan said:
we know vector<bool> is 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<bool> anyways,
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<char>. It will take more
memory than std::vector<bool>, though (about 8 times as much).
 
G

Gennaro Prota

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

we know vector<bool> is 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/>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,171
Messages
2,570,935
Members
47,472
Latest member
KarissaBor

Latest Threads

Top