473,769 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3047
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).
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
5320
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 a bool: class FakeBool { public: FakeBool() : b_(false) {} FakeBool(bool b) : b_(b) {} operator bool() { return b_; }
12
6732
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 (myboolarray) { // do this... } if not, is there another solution?
8
4107
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
5372
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 possible to "spoof" std::vector into implementing a "true" vector of bool rather than the specialisation? Say I do: typedef bool boolreally; std::vector<booleallybvec;
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10212
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10047
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6674
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.