Archived

This topic is now archived and is closed to further replies.

mass data storage

This topic is 5132 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

what type of data storgae is best to store 400 people, with 20 attributes each - i was thinking mayb linked lists but undecided - im still pretty new to c++ so bear with. thanks for ur help in advance

Share this post


Link to post
Share on other sites
A database should be the perfect choice, but if you mean c++, std::vector ... stored is a class or struct definition of the people... that should do it.

Share this post


Link to post
Share on other sites
Depending of course on whether it will be accessed in a random or linear fashion - I believe lists are more appropriate for linear accesses, and vectors for more random accesses?



"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
lists aren''t any better than vectors (arrays) for linear access. in fact the extra level of indirection needed makes them less efficient for such a purpose. they are however, better for insertions and deletions as the reordering required only affects one node, whereas with vectors the worst case impact is to require reshuffling of the entire array.

Daz_mk, there are many different types of data structures, a few of which are included in C++''s std namespace. and as with any type of data use, what you do to/with the data is as important as what the data is. in many cases what you do to/with the data will be the deciding factor as to what data structure is appropriate.

so what do you intend to do to/with this data? it could be that std::map is more appropriate for instance, if you wished to store/use relations between the people or the people''s attributes, but it really all depends upon what you want to do to/with the data.

Share this post


Link to post
Share on other sites
right, well basically for my game, im doing a football (soccer if ur american) manager game, where i have lke 400 - odd set players with about 20 attributes each like passing, technique, etc - but this data shouldn''t b able to change in the game unless hes improved, - young uncoming player. i had a bit of experience with c++, its just choosing the right method so it dont lead to problems later.
thanks

Share this post


Link to post
Share on other sites
quote:
Original post by Enselic
Registred users may actually edit their posts.


true


regarding the anonymous users post though, he is right

if you are using a static array, use std:vector
BUT
if you want to use a linked list, use
std:list

Vector is a resizable array that has fast appending and deleting from the end of its array.
List has fast insertion, deleting and swapping from anywhere in its array. It is very minutely slower (you''ll probably never be able to measure it, my guess is that reading 100 of them may give you 1 clock cycle extra or less - could time it but couldn''t be arsed as its fast enough) to access the data, but for a linked list it is perfect. That is because std:list IS a linked list

It has sorting and everything in there as well, like most of the std:: functions.

Share this post


Link to post
Share on other sites
If you are only storing 400 players, why call it ''mass storage'' ?

Anyway, you said the playerlist doesn''t change. So linked lists are unneccesary, as you won''t be inserting/sorting/merging etc.

Since the list will always hold 400 players, and not 0 - 400, the best choice would be an array of structs. Then you can use an array of 16 ints for each team to index into this array for teams. With 500 bytes per struct you will use maybe 200K, not a lot.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
sorry, i think i can understand what your saying but can you explain a bit better tho

Share this post


Link to post
Share on other sites
rite, so by doin this method would i be able to access them thoroughtout the game also when i need to and would it b quick to create all of the players upon startup? - thanks again

Share this post


Link to post
Share on other sites
if there are always 400 players no matter what, an array of struct/class would be the most efficient/memory effective way to go. Just define:

cPlayer playerarray[400];

assuming cPlayer is your player class/struct

Share this post


Link to post
Share on other sites