473,396 Members | 1,866 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,396 software developers and data experts.

Using Deque :: Iterator?

Hello

I have the following declaration in my code,

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

std::deque<mHandleObjm_Hand;

std::deque<mHandleObj>::iterator m_Itr;
************************************************** ****************

Now in the actual implementation, there is...

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

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

mHandleObj* pObj = new mHandleObj;

pObj->h = hHand ;

m_Hand.push_back(*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 2916
Donos wrote:
I have the following declaration in my code,

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

std::deque<mHandleObjm_Hand;

std::deque<mHandleObj>::iterator m_Itr;
************************************************** ****************

Now in the actual implementation, there is...

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

HANDLE hHand = ::CreateEvent(NULL,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_back(*pObj );
Seems like a waste of memory. Why do you need 'new'? Why can't you
simply do

mHandleObj m = { hHand };
m_Hand.push_back(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
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...
34
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...
19
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...
5
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...
8
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
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 * ...
7
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
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'...
2
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...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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,...

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.