Using Vectors
I am currently working on vectors and I understand them but I would understand them better if I knew where in a program they would be used.
Anytime you need a list that dynamically grows. A bunch of games will use a vector or a linked list to hold things like bullets in a scene, a list of clients connected to a small server, or even as a rendering queue. They are quite handy.
I'm assuming you mean std::vector and not a mathematical vector.
A vector is just a more flexible and easier to use array. In a game, you might use one to store a group of structures that represent your characters, or the tiles to make up a 2D map, or vertices that make up a 3D model, etc.
You would use a vector whever you need a group that you can access by index (such as group[3]). They are also handy because you can pre-allocate the memory and use it later (so, for example, I have a vector of 500 "characters", I can initialize memory for them vector at loading time and then add the characters when needed at runtime).
I hope this helps a bit.
A vector is just a more flexible and easier to use array. In a game, you might use one to store a group of structures that represent your characters, or the tiles to make up a 2D map, or vertices that make up a 3D model, etc.
You would use a vector whever you need a group that you can access by index (such as group[3]). They are also handy because you can pre-allocate the memory and use it later (so, for example, I have a vector of 500 "characters", I can initialize memory for them vector at loading time and then add the characters when needed at runtime).
I hope this helps a bit.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement