468,737 Members | 2,560 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,737 developers. It's quick & easy.

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 2662
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Frederik Himpe | last post: by
5 posts views Thread by yancheng.cheok | last post: by
8 posts views Thread by Gernot Frisch | last post: by
12 posts views Thread by arnuld | last post: by
7 posts views Thread by Donos | last post: by
1 post views Thread by subramanian100in | last post: by
2 posts views Thread by subramanian100in | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.