reading from and writing to a global linked list properly
Hey guys. I imagine this question is a pretty common one that I thought I could answer but I cannot. Here is my situation:
My program reads data (live) and stores it into my std::list<> which is global in my program. This list grows and within it, there is one other std::list<> which also grows. (the list is a list of structs that itself has one other list as a member)
ie:
struct items{
char data[MAX];
std::list<char*> data;
};
std::list<items> mainlist;
So as I get more live data if there is more data for a particular object, the data list in that object is concatenated. If the data is for a new object then a new list is created and that data is put into that list's data list as a first entry.
My problem is when I want to display this data. In my program I have a while loop that iterates over the global std::list and for each of those it will print out each item in the data list. It seems to work ok, but sometimes strange things happen such as:
showing data:
somedata
somemore data
showing data:
somedata
somemore data
showing data:
someother data
showing data:
somemore data
It seems to randomly be missing information and then later it will show some of the information. I'd expect that for each "showing data" I'd have an increasing amount of ALL information, not just a random set of information.
I'm pretty sure I'm doing something silly, and that there are smarter ways to make this work.
Any help is greatly appreciated!
|