By the way, the original post was made in 2006. emailus resurrected this thread.
Oops...
Anyway, it still appears to be a hot topic
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio: FeinWindows - replacement windows manager for Visual Studio, and more...
2) std::vector does not have "to construct their ctors at least twice"
(maybe the poster was trying to say something about when re-allocation
occurs ... but CArray needs to do re-allocation also)
3) vector has a richer array of public functions (pun intended). Also,
it works better with the <algorithm>
4) a vector has at least as good of performance as CArray ... and in
some cases much faster. The usual situation is when you are reading
data from a file and adding to the container (and you do not know
the number of data elements in the file). Below is code to simulate
this ...
Code:
struct A
{
int x,y;
};
const int n = 1000000;
vector<A> v;
A a;
for (int i=0; i<n; ++i)
{
v.push_back(a);
}
"STL much faster than MFC" is just a legend.
Possible, that was true long time ago.
I have made some benchmarks for CStringArray vs. std::vector<CString> and the performance differences were small. For example, filling time resulted almost equal while sorting, a little bit faster for CStringArray (attached here is a screenshot as well as the VS2005 solution).
At least, if use a modern compiler and run under a modern computer, does not make sense anymore to mix STL in an MFC application for performance reasons.
On the other hand, as I already said many times before, mixing different libraries in a project makes the code harder to understand and maintain.
So again: DO NOT use STL in an MFC project if it's not absolutelly necessary.
Last edited by ovidiucucu; June 30th, 2010 at 03:46 AM.
Reason: typo
I'd recommend the opposite. Prefer standard C++. Always use as much standard C++ as possible.
I've created a lot of customised MFC components and their interfaces are, as far as possible, STL, as the generic (and possibly cross platform) libraries are all STL based.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
Well then, what about "In an STL project try to isolate STL as much as possible"...
Don't get confused by naming.
An MFC project is the Microsoft teminology for any C++ program which makes use of the MFC.
In reality it's a C++ project based on the MFC application framework. It's easy to get goobled up by the framework. It's the same if you use Qt.
Regardless of whether you're using MFC or Qt my advice is the same. Prefer standard C++ whenever possible. Don't allow the framework to take over your program. You're the captain. Fight mutiny with standard C++ or you'll lose the ship.
Now serious.
A little bit better saying is: If for some reasons you are using STL in an MFC-based project, then put STL and MFC stuff in separate modules.
Now serious.
A little bit better saying is:
If for some reasons you are using STL in an MFC-based project, then put STL and MFC stuff in separate modules.
No, you should use STL and the rest of the C++ standard library freely in your program.
It's MFC that should be but used as little as possible and be isolated in separate modules.
An MFC project is the Microsoft teminology for any C++ program which makes use of the MFC.
In reality it's a C++ project based on the MFC application framework. It's easy to get goobled up by the framework. It's the same if you use Qt.
Regardless of whether you're using MFC or Qt my advice is the same. Prefer standard C++ whenever possible. Don't allow the framework to take over your program. You're the captain. Fight mutiny with standard C++ or you'll lose the ship.
Looks like thoughts from someone with no or with not too much experience in software industry.
In reality, even you are a little programming genius, you'll get nothing trying to reinvent the wheel instead of using some already made stuff in a framework.
In contrary, your managers will complain for delayed deadlines, your colleagues will swear you for hard to understand and buggy code, and so on.
, you'll get nothing trying to reinvent the wheel instead of using some already made stuff in a framework.
Who's talking about re-inventing the wheel? The STL is'already made stuff in a framework'.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
Looks like thoughts from someone with no or with not too much experience in software industry.
In reality, even you are a little programming genius, you'll get nothing trying to reinvent the wheel instead of using some already made stuff in a framework.
In contrary, your managers will complain for delayed deadlines, your colleagues will swear you for hard to understand and buggy code, and so on.
This is the real reality, Captain!
Using an application framework is a strategic decision because once you've made your choise you're effectively stuck. But regardless of whether you're stuck with MFC or Qt or something else there's still plenty of room to decrease the coupling induced by the framework. One way is to prefer standard C++ over the framework and another is to isolate the framework as much as possible, like I suggested.
So it's not a question of reinventing the wheel. It's a question of preferring standard C++ whenever this is a reasonable option.
I still don't understand what you meant by 're-inventing the wheel'
Nobody said anything about doing that
The comment was that, if you have the choice between using MFC or STL, then STL was the better option.
"It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
Richard P. Feynman
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.