Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

HELP!!!Problem in using list in c++

Status
Not open for further replies.

Alexander Yin

Junior Member level 2
Junior Member level 2
Joined
May 29, 2007
Messages
21
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Location
Finland
Activity points
1,450
hi everybody,

I'm using the list template as a channel between a master and a slave. I use "push_back()" to insert a message into the list and "pop_front()" from the front the list in each cycle. But maybe since my message is too long (sizeof(message)=220), although the program is compilable, it can only run to the second cycle and pop out the debug error:

HEAP CORRUPTION DETECTED: after Normal block(#182) at 0x00389730. CRT detected that the application wrote to memory after end of heap butter.

If I delete the "pop_front()" function, the program can run to the end of the program.

Could somebody please tell me how to extend the memory for this list? or how to solve this problem.

Thank a lot.
 

I dont think the list is the correct container to use.
The function 'list.pop_front()' removes the first element but does not return it.
The list is a double linked list so you can insert and remove elements easily which you dont seem to need.
A vector should do the job which you can use like an array. Not tested but try something like:

std::vector<string> myString;
myString.reserve(NUMBER_OF_STRINGS);
myString[1] = "Hello";
cout << myString[1];
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top