• Advertisement
Sign in to follow this  

Using Vectors

This topic is 4300 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement