Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
BroadcastCommunity.qnx.com will be offline from May 31 6:00pm until June 2 12:00AM for upcoming system upgrades. For more information please go to https://community.qnx.com/sf/discussion/do/listPosts/projects.bazaar/discussion.bazaar.topc28418
Forum Topic - First element data corruption in a vector: Page 1 of 2 (2 Items)
   
First element data corruption in a vector  
Hi all, I noticed that whenever I push_pack() a structure into a vector, there will be incidents when the content in the
 first element always get corrupted. This does not happen consistently but rather randomly.

my structure is defined as follows:
struct myStruct 
{
    uint32_t content1;
    uint32_t content2;
    uint32_t content3;
    uint32_t content4;
}

Usage is as follows:
class myClass
{
    public:
        void Update();
        void Retrieve(std::vector<myStruct> &list);
    private:
        std::vector<myStruct> m_list;
}
void myClass::Update()
{
    myStruct temp;

    // performing operations to fill up contents in myStruct

    m_list.push_back(temp);
}

void myClass::Retrieve( std::vector<myStruct> &list)
{
    for(uint32_t i=0; i<m_list.size(); i++)
        std::cout << m_list[i].content1 << std::endl;
    list = m_list;
}

I noticed that when I called Retrieve(), the content1 is changed randomly although I have verified that the contents 
inside are per what was pushed in in Update(). I am currently using QNX 6.6.0.

May I know what is causing this problem? Thanks.