473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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.

Jul 31 '08 #1
3 3022
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<boolanyways,
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).
Jul 31 '08 #2
On 2008-07-31 12:35:49 -0400, Yuan <yu******@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)

Jul 31 '08 #3
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.
Jul 31 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jeff Paciga | last post by:
I have been reading about the problems associated with vector<bool>. Unfortunately, the usual work-arounds aren't viable for me, but I have never seen anyone mention using a class that behaves like...
12
by: Piotr | last post by:
In effective STL, it said one should not use vector<bool> but use dequeue<bool> instead. But can dequeue<bool> has random access iterator? and I do this? dequeue<bool> myboolarray; if...
8
by: Chris Dams | last post by:
Dear all, The following is accepted by the compiler template <class Tclass test { public: typedef vector<int>::reference rt; }; but after the change int -T, obtaining the code fragment,
8
by: Lionel B | last post by:
On my platform I find that the std::vector<boolspecialisation incurs a significant performance hit in some circumstances (when compared, say, to std::vector<intprogrammed analagously). Is it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.