Padmanabhan
July 3rd, 1998, 10:58 AM
Recently I had the oppurtunity to work on COBArray.
I was using the Add function of CObArray to add elements to the Array.
To enhance the performance I called SetSize function of CObArray in
my constructor.
Now when I started to retrieve the elements from the Array using the
Index, I was surprised that the elements where not at that index.
After much struggle I learnt the following :
SetSize function sets a variable in CObArray that specifies the
index of last element in the Array.
Add function uses this variable to position the new element.
For eg :
Initially you could have calls to Add as
Ar.Add(new A); // assuming the element is added to position 0
If you had called Ar.SetSize(200) earlier, the previous call to
Add will put the element at position 201 and not at 0.
From the explaination given in help of MFC, I just thought that
SetSize function helps manage the memory better. But its action
was something different.
I am not sure if this is a bug or it is designed that way.
I was using the Add function of CObArray to add elements to the Array.
To enhance the performance I called SetSize function of CObArray in
my constructor.
Now when I started to retrieve the elements from the Array using the
Index, I was surprised that the elements where not at that index.
After much struggle I learnt the following :
SetSize function sets a variable in CObArray that specifies the
index of last element in the Array.
Add function uses this variable to position the new element.
For eg :
Initially you could have calls to Add as
Ar.Add(new A); // assuming the element is added to position 0
If you had called Ar.SetSize(200) earlier, the previous call to
Add will put the element at position 201 and not at 0.
From the explaination given in help of MFC, I just thought that
SetSize function helps manage the memory better. But its action
was something different.
I am not sure if this is a bug or it is designed that way.