Quote:
Originally Posted by http://www.sourcewiki.org/wiki/index.php/Technical_FAQ
Is there a particular advantage to generic utility classes like CUtlVector or can i just use the standard template library?
For those of you who aren't familiar with the Standard Template Library ( http://www.sgi.com/tech/stl/), it's a set of very useful data structures and algorithms provided by most development environments. However, a lot of the data structures in it aren't needed for HL2, and the ones that are useful can probably be optimized for HL2-specific use. So Valve has implemented their own common set of data structures, the CUtl* classes. Most of these are going to be more efficient than their more-general STL counterpart. Also, they're already compiled into HL2, so using them won't increase your code size at all. However, to take advantage of the STL, you'd would need to include all of the relevant code - and the STL is comparatively large. So, in short, use CUtl* classes over STL classes if at all possible. If you can't live without an STL class, see if you can build it cheaply off of some CUtl* classes.
|
Unless performance is statistically greater in significant portions across every platform, I do not believe in the statement from this article.
A) Efficiency
It is not necessarily the same across every platform. ValvE uses optimizations in windows heavily, with some linux optimizations when they can find the time/resources.
STL has been created for efficiency across every platform, although there are optimizations that each library ( for the specific platform ) has made for its own platform.
In the context of HL2 modification programming, CUtl* may be more efficient with specific HL2 structures that were designed to work specifically with those, since it's the inherant design of the set of templates.
However, I wouldn't assume that it's more efficient just because ValvE wrote them. ValvE coders may have specialties, yet they must rely on their game programming expertise such that they have their jobs. On the other hand, the STL coders have been working on the code specifically for any structure of data.
B) Binary size bloating
I see this as a moot point. Go ahead and statically link your plugin/mod against STL. Your binary size may increase, but, with the cost of disk space decreasing, and with the possible tradeoff of increased performance/efficiency, it is a relatively nice gain.
C) Compatibility
Mattie made a good point in the other post with the problems with older versions of gcc and libstdc++. Sometimes STL may not be compatible with older versions of gcc, HOWEVER, HL2 plugins require 3.4.X, and thus, get your lazy self into gear and upgrade gcc/libstdc++ whenever it is possible.
This shouldn't be an issue with CUtl*, since ValvE had made sure that it was compatible across both platforms that they support (win32 and linux).
However, what if you want to use an algorithm in the industry, outside of HL2? You would have to completely rewrite it using STL, and that would be a waste of an important concept of C++: reusability.
D) STL just makes sense
I can't add much to this except the examples of push_back and pop, and this isn't certainly a strong argument.
Although I am not an assembly language guru, nor am I anywhere above intermediate, however, those terms specify push and pop as ways of manipulating data on the stack.
I don't see why CUtl* has to move away from this, as you push the data onto the container, then you pop it off. AddTo* and Remove makes more sense in plain English, and probably appeals to those without a background in lower level languages, however, I don't see the sense in renaming them to appeal to other programmers.
Just understanding what each function does should be enough to use it, yet if you don't have time to learn the accepted standard, then I guess you can use the nonstandard.
I will see if I can find someone who can run extensive testing to see how fast it is to use a CUtlVector versus std::vector of int, std::string, and some other structure that I'll have to lookup, but specifically a data structure that ValvE has created for HL2. Maybe they can test different versions of gcc/libstdc++ that has different algorithms for std::vector (if it has changed at all recently) as well.
I will definitely look into this so that I can support my claims, or concede them.
Please post constructive criticism, don't flame me if you find credible data that makes my point absolutely wrong. I'm not trying to attack anyone who loves the CUtl*, either, but rather, I would like to show those who don't know about STL to look into it as a possibility.