Sign in to follow this  
Kenny77

Using Vectors

Recommended Posts

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this