STL question
I have to read a 3D model to display it (with OpenGL) and I
was wondering if the STL containers and algorithms are fast
enought to do the job. All the examples that I have read use
arrays and pointers, but it may be easy to program using
the STL library.
Anyone uses the STL for game/graphics programming?
Thanks!
The STL containers are great, but make sure you use the right one for job. For example, don''t use a
However, I don''t particularly like the interface to any of the STL classes, so I always roll my own. Since the only STL class I''d use is
list
when you will be accessing elements non-sequentially.However, I don''t particularly like the interface to any of the STL classes, so I always roll my own. Since the only STL class I''d use is
vector
as a dynamic array class, rolling my own is very trivial.
In a lot of ways, the STL is like C++ itself. If you use it correctly, it can be extremely efficient. However, if you use it poorly, it can really slow you down.
The best way to learn how to use the STL is to read up on it. My favorite STL book is "STL Tutorial and Reference Guide." It goes into some detail about efficiency and what things work better than others. Once you understand what''s going on underneath the hood, you can easily see what''s going to cause performance problems.
On a side note, there''s nothing wrong with arrays, so don''t think of this as a choice between using arrays or using STL containers. In most cases, you can use an array as an STL container. You just need to learn which container makes sense for your design. If you know how big your container will be in advance, arrays are great. If not, a more generic container like std::vector might be best.
The best way to learn how to use the STL is to read up on it. My favorite STL book is "STL Tutorial and Reference Guide." It goes into some detail about efficiency and what things work better than others. Once you understand what''s going on underneath the hood, you can easily see what''s going to cause performance problems.
On a side note, there''s nothing wrong with arrays, so don''t think of this as a choice between using arrays or using STL containers. In most cases, you can use an array as an STL container. You just need to learn which container makes sense for your design. If you know how big your container will be in advance, arrays are great. If not, a more generic container like std::vector might be best.
i use STL as much as possible... the container''s are quite fast ..
vector , map , iterator and algorithms are really great ..
vector , map , iterator and algorithms are really great ..
Whew...
The class I''m taking in college right now is over data structures, and our projects consisted of writing a program that used some container of the STL, then rewriting our own container (such as my_vector, my_list, my_map, etc.) and getting our program to work using the STL''s functions and methods. It was not fun doing your own memory management and taking care of pointers all over the place and keeping track of iterators and nodes as subclasses of the main template class...whew, I can say I have a decent understanding of the STL, and I definetly have a great appreciation of it and use it as much as I can.
I will say this. The STL was written with speed being the primary concern, so all of the containers and functions are about as efficient as you''re going to get. I''m sure there are optimizations that could be done for specific cases, but for general cases which the STL supports, it''s extremely well written and efficient. Remember, some of the top programmers in the world got together and worked on the STL over a LONG period of time. So 1) you''d have to be a world-class top level programmer, and 2) you''d have to work with a bunch of other world-class top level programmers for months or years to get something as nice as the STL. So don''t try to reinvent the wheel, use the STL, it''s like one badass gift.
The class I''m taking in college right now is over data structures, and our projects consisted of writing a program that used some container of the STL, then rewriting our own container (such as my_vector, my_list, my_map, etc.) and getting our program to work using the STL''s functions and methods. It was not fun doing your own memory management and taking care of pointers all over the place and keeping track of iterators and nodes as subclasses of the main template class...whew, I can say I have a decent understanding of the STL, and I definetly have a great appreciation of it and use it as much as I can.
I will say this. The STL was written with speed being the primary concern, so all of the containers and functions are about as efficient as you''re going to get. I''m sure there are optimizations that could be done for specific cases, but for general cases which the STL supports, it''s extremely well written and efficient. Remember, some of the top programmers in the world got together and worked on the STL over a LONG period of time. So 1) you''d have to be a world-class top level programmer, and 2) you''d have to work with a bunch of other world-class top level programmers for months or years to get something as nice as the STL. So don''t try to reinvent the wheel, use the STL, it''s like one badass gift.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement