vector template pyramid ?? iterator unexpected behaviour

Hi there,




there is a vector pyramid as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
template <class T>
class cObject1
{
   public: 

   T m_buffer;
  
   int sth;
   void somefunction();
};

.
.
.
.
template <class T>
class cObjectN
{
   public: 

   T m_buffer;
  
   int sth;
   void somefunction();

};

int main()
{
     //// pyramid
     cObjectN pyramid<vector<(cObjectN-1)<vector<(cObejectN-2)< ... vector<int> > > > > >;
     
     /// The pyramid is constantly shuffling buffer around on the different 
     /// layers using swap(iterator1, iterator2), creating new entries and 
     /// popping entries

     while(true)
     {
       for(int i = 0; i<X; ++i)
       {
         if(should delete node)
         {
           pop(pyramid layerX objectY);
         }
         
         if(should create node)
         {
           cObjectZ objZ<....>;
           init buffer of objZ;
           
           
           (pyramid layerX).push_back(vector<cObjectZ<...> >);
           init (pyramid layerX)[size - 1]
           /// set the m_buffer, where m_buffer of objZ itself is empty
           (pyramid layerX)[size - 1].m_buffer = objZ; /// ??? is this appropriate??? 

         }
         swap(pyramid layerX vector position Y, pyramid layerX vector position H);
       }
     }
}


After a couple of million operations on the pyramid strange effects in the pyramid are observed. On the lowest layer is a vector<int>, representing some object to compute a Number. This value can be evaluated and checked weather it is still valid or not. After a couple million iterations the program says the value is no longer valid. However, if the int values in the vector are being printed and backfeeded into a new vector, in a new program. The very same entries leading to a false value are now being evaluated to be valid.

What is being guessed is the equal operations are somehow messing up the memory, so I ask for your advice. The only piece of code left, where equal operators are being used are for initialization, should these equal operators are being replace with something else, like copy or set etc.??

Or should the problem occur somewhere else?

It is rather difficult to pinpoint the problem as it can be told when it happens but not exactly where in the code and the program is running for 4h before these effects start to occur. As stated the value is computed to be valid using the actual entries from the vector, so something else goes wrong and the iterator going over the vector to compute the value might (not sure if this is the problem) mess up. Please note, there are no malloc, alloc, new or other means of memory allocation calls in the program, all routines to allocate and deallocate memory are being used from std., e.g. push_back etc.

This problem has been hunting my mind for a couple weeks now. Help or suggestions?


Thank you,

Gregor.
Last edited on
Topic archived. No new replies allowed.