Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - First element data corruption in a vector: (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.
Re: First element data corruption in a vector  
Hi Ong,

This is QNX 4 discussion board, but you asked about QNX 6.6. Please post your question in right forum. It’d be great to
 add a full minimal example (including main() and Makefile) to illustrate the issue.

Respectfully,
Oleg

24 июня 2015 г., в 5:41:32, Ong Di Yong <community-noreply@qnx.com> написал:

> 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.
> 
> 
> 
> _______________________________________________
> 
> QNX4 Community Support
> http://community.qnx.com/sf/go/post114010
> To cancel your subscription to this discussion, please e-mail qnx4-community-unsubscribe@community.qnx.com