STD: Map iterator offset error

Source: Internet
Author: User
Written yesterday Code After one day with the boss, I found the problem but did not solve it. Google and Baidu both found the answer.

Read the following code.
------------------------------
// Structure Definition
Typedef struct _ stru_cutpicinfo
{
String strcpurl; // address
String strmname; // The name of the clip.
Stru_cutpicinfo ()
{
Strmname = "";
Strcpurl = "";
};
} Stru_cutpicinfo, * lpstru_cutpicinfo;
Typedef STD: Map <int, stru_cutpicinfo> cutpic_list, * lpcutpic_list; // int -- Material ID

---------------------------------
// Fill
Cutpic_list m_adcutpiclist;
M_mapcs.lock ();
If (asxmsginfo. m_adcutpiclist.size () <3)
{
Stru_cutpicinfo lcpinfo;
Lcpinfo. strcpurl = videoaditem. mstrcutpicurl;
Lcpinfo. strmname = videoaditem. stritemname;
Asxmsginfo. m_adcutpiclist.insert (make_pair (liadid, lcpinfo ));
}
M_mapcs.unlock ();

--------------------------------------------------
Then, send a message to the control.
Sendmessage (...,..., (wparam) (lpvoid) & m_adcutpiclist ,...);

---------------------------
After receiving the message
Cutpic_list * mpcplist = (cutpiclist *) (lpvoid) aparam; // here, aparam is the address of the map structure.
Cutpic_list: iterator itr = mpcplist-> begin ();
While (itr! = Mpcplist-> end ())
{
Int IID = itr-> first;
String strurl = itr-> second. strcpurl;
String strname = itr-> second. strmname;
++ Itr;
}

well, let's talk about the error. In the while loop, the data can be read out in the first round. After the iterator increases,
it is found that the iterator points to an empty position, memory leakage. I checked a lot of information and couldn't solve the problem.
finally, I switched map to vector, which solved this weird problem. Does map iterator have some restrictions or rules?
I hope my friends who have encountered this problem can help me find out what the problem is.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.