Re: Is CArray best for this...
David Ching schrieb:
"Giovanni Dicanio" <giovanni.dicanio@invalid.com> wrote in message
news:uG2dxrTWIHA.5980@TK2MSFTNGP04.phx.gbl...
Hi David,
I think that you are right, only if the intial size of CArray is setted
properly...
But the grow policy of CArray is not good, IIRC. In fact I think that
CArray grows using a *fixed constant*. Instead, std::vector's amount of
growth is *proportional* to the current capacity() (I think they use a
factor of 2).
Yes, the factor of 2 is an excellent algorithm, but I've not taken advantage
of it simply by setting intial size of CArray.
I often have cases where the size of the array is not known when you start
puting elements into it. Examples could be: parsing XML with a streaming parser
and adding some found elements in an array, storing the lines of a text file,
stroing the results of a database query (getting the size of a query result can
be an expensive operation) etc.
These collection classes are
a comfort thing. They are meant to extend the base types available in a
language, and in my mind CArray is simple for an MFC programmer to use,
whereas the std::vector and other STL is clearly foreign with little attempt
made to make it attractive for a Windows programmer. Sometimes I think
Windows is the _last_ platform considered in making cross platform libraries
such as these.
I disagree here. I do not see how in any way a std::vector can be "foreign" to
windows. The only MFC like thing about CArray/CList I see is the naming
convention. I can not remember any Windows/MFC API that expects or returns
CArray or CList.
On the contray, I think that CArray is more "foreign" as std::vector since
std::vector is part of the C++ standard and CArray is not. What do you think is
missing from std::vector to make it attractive to windows developers?
So I only embrace a foreign library like STL for a clearcut advantage, and
not for things like David W. said that can be easily worked around.
See, use std::vector and you do not need any work around.
The std containers and iterators look strange when you start using them, but
their concept is much better thought out than the MFC collections.
Personal preference, David W... I also don't use Seamonkey! ;)
I thought the same when I first saw the std library, but I changed my mind the
better technology got me.
Norbert