29.06.2011, 17:12
You can use vectors and maps to store data (variables). They use dynamic memory, and are very efficient.
Vectors are sequence containers, meaning they remember the order in which the data is stored. So if you add playerids to a vector: you can loop through the vector, and not do any needless loops. Similar to foreach but not as fast. A simple example, but I'm sure you can think of other uses for a vector.
Maps are associative containers, meaning they use a key and a value (similar to a 2D array using an enum the enum would be the key). Maps DO NOT remember the order in which data is stored, usually the keys are sorted in ascending order, (there are ways to change which order). With maps an example would be an inventory system - the key could be the name of the item and the value can be the amount of items the player has. Again a simple example...
There are a lot more features to them than that also.
Vectors are sequence containers, meaning they remember the order in which the data is stored. So if you add playerids to a vector: you can loop through the vector, and not do any needless loops. Similar to foreach but not as fast. A simple example, but I'm sure you can think of other uses for a vector.
Maps are associative containers, meaning they use a key and a value (similar to a 2D array using an enum the enum would be the key). Maps DO NOT remember the order in which data is stored, usually the keys are sorted in ascending order, (there are ways to change which order). With maps an example would be an inventory system - the key could be the name of the item and the value can be the amount of items the player has. Again a simple example...
There are a lot more features to them than that also.