473,795 Members | 3,231 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Deque :: Iterator?

Hello

I have the following declaration in my code,

*************** *************** *************** *************** ******
struct mHandleObj
{
HANDLE h;
};

std::deque<mHan dleObjm_Hand;

std::deque<mHan dleObj>::iterat or m_Itr;
*************** *************** *************** *************** ******

Now in the actual implementation, there is...

*************** *************** *************** *************** ******

HANDLE hHand = ::CreateEvent(N ULL,FALSE,FALSE ,NULL);

mHandleObj* pObj = new mHandleObj;

pObj->h = hHand ;

m_Hand.push_bac k(*pObj );

This is where i push in data to Deque. After this i use the following
code to take data out of Deque.

m_Itr = m_Hand.begin();
mHandleObj& pWro = *m_Itr;

And then i do,

m_Hand.pop_back ();
*************** *************** *************** **************

This works fine in a few loops and after that, what happens is that at
some place the Deque breaks.
There is a memory exception and the debugger goes into some
"dbgheap.c" file which is associated with Visual Studio.

Is there anything wrong in this code?

Oct 22 '07 #1
1 2935
Donos wrote:
I have the following declaration in my code,

*************** *************** *************** *************** ******
struct mHandleObj
{
HANDLE h;
};

std::deque<mHan dleObjm_Hand;

std::deque<mHan dleObj>::iterat or m_Itr;
*************** *************** *************** *************** ******

Now in the actual implementation, there is...

*************** *************** *************** *************** ******

HANDLE hHand = ::CreateEvent(N ULL,FALSE,FALSE ,NULL);
Since 'CreateEvent' is not a standard function, we'll have to take
your word that it actually works and does what you need.
mHandleObj* pObj = new mHandleObj;

pObj->h = hHand ;

m_Hand.push_bac k(*pObj );
Seems like a waste of memory. Why do you need 'new'? Why can't you
simply do

mHandleObj m = { hHand };
m_Hand.push_bac k(m);

?
>
This is where i push in data to Deque. After this i use the following
code to take data out of Deque.

m_Itr = m_Hand.begin();
mHandleObj& pWro = *m_Itr;

And then i do,

m_Hand.pop_back ();
pop_back does not take out the object pointed to by 'm_Hand.begin() '.
It takes out the _last_ element. Consider using 'pop_front'.
*************** *************** *************** **************

This works fine in a few loops and after that, what happens is that at
some place the Deque breaks.
At what place? What do you mean by "breaks"?
There is a memory exception and the debugger goes into some
"dbgheap.c" file which is associated with Visual Studio.
OK.
Is there anything wrong in this code?
What code? The bits and pieces you cared to post seem fine (albeit
using 'new' and 'pop_back' inappropriately ). Nothing can be said
about the rest of it, of course, since you decided to withhold it.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Oct 22 '07 #2

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

Similar topics

2
1629
by: Frederik Himpe | last post by:
I'm implementing a SAX handler with libxml++. I have this piece of code: void PalamedeParser::on_start_element(const std::string &name, const AttributeList &attributes) { AttributeList::iterator it = attributes.begin(); with AttributeList defined as typedef std::deque< Attribute > xmlpp::SaxParser::AttributeList On the initialization of the iterator, I got this error:
34
3695
by: Dennis | last post by:
I would like to dynamically allocate in a sub a 2 dimensional Array float *myarray = new float ; of course I get an error. How do you allocate a 2D array using the New operator? I currently use static float gxy;
19
4381
by: chris | last post by:
Hello, I've recently been trying to understand the various structures supplied by c++, and the one I find most confusing is deque. One quick question about this. It seems most implementations of deque are quite complex. Why couldn't I implement deque with a couple of vectors V,W where the deque is the element of V in reverse order followed by W? This would appear to me to satisfy all the conditions, and be significantly simpler. Am I...
5
6159
by: yancheng.cheok | last post by:
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!
8
2968
by: Gernot Frisch | last post by:
std::deque<intd; d.push_front(13); int* p13 = &d.begin(); d.push_front(1); d.push_back(2); Can I be safe, that p13 points to 13? I mean, unless I erase the 13, of course.
12
2653
by: arnuld | last post by:
It works fine. any advice on making it better or if I can improve my C++ coding skills: /* C++ Primer - 4/e * * Chapter 9 - Sequential Containers * exercise 9.18 - STATEMENT * Write a program to copy elements from a list of "ints" * to 2 "deques". The list elements that are even should go into one deque * and even elements should go into 2nd deque.
7
22700
by: Donos | last post by:
Hello I have a Queue which is declared as, std::queue<unsigned charm_Queue; I push data into this queue. Now i want to take the data out of this queue using Iterator.
1
2541
by: subramanian100in | last post by:
Suppose I have vector<intvi; deque<intdi; list<intli; Suppose all of these containers have some elements. Suppose 'v_iter' is an iterator pointing to some element in 'vi'. Suppose 'v_beg' and 'v_end' are valid iterators pointing to some
2
2415
by: subramanian100in | last post by:
In ISO/IEC 14882:2003 document, in the section '23.2.1.3 deque modifiers', the following is mentioned: iterator insert(iterator position, const T& x); void insert(iterator position, size_type n, const T& x); template <class InputIterator> void insert(iterator position, InputIterator first, InputIterator last);
0
9672
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
10435
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...
1
10163
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
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
9037
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5436
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...
2
3721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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.