   Lists
  I am doing a setup of my game engine and need some help.I am storing all of my mesh data in an object and need a list of them. Each model has a name string and a pointer to the respective data. I was thinking of using a set or map template (I don't remember how they work but I know they had searching by keywords) or none and have the developer keep track of his own models.Which do you think would be more efficient? More friendly? Easier to manage?   
Quote:Original post by ShlaklavaI am doing a setup of my game engine and need some help.I am storing all of my mesh data in an object and need a list of them. Each model has a name string and a pointer to the respective data. I was thinking of using a set or map template (I don't remember how they work but I know they had searching by keywords) or none and have the developer keep track of his own models.Which do you think would be more efficient? More friendly? Easier to manage?The map. (Sets are for when you don't need to look things up, just keep them unique according to a "key" that's already embedded in the object". Pull out the name, and just make the "model" be a *wrapped* pointer (typically an already existing smart pointer, such as boost::shared_ptr) to the mesh data.Also, be aware that "list" typically implies a *linked* list; the more general term is "container" (for all of these things) or "sequence" (for those which are ordered, rather than being sorted or providing a key-lookup).   ;  If performance is an issue, consider handles.Rather than mapping from name to pointer, resolve the name to handle, then use the handle to look up the pointer.Looking up by string requires comparison between strings, which will result in quite inefficient iteration. If your handles are integers, they'll result in an int comparison.This is only relevant if you do lookups frequently. If you do it once only, there's no benefit.   ;  Zahlman's right, use a map:typedef boost::shared_ptr<Model> ModelPointer;typedef std::map< std::string, ModelPointer > ModelMap;ModelMap models;ModelPointer myModel( new Model() );models["DougThePlumber"] = myModel;// Later on...ModelPointer doug = models["DougThePlumber"];Ofcourse you don't have to use a string, you could use integer handles instead, inwhich case a vector would be more adequate than a map.   ;Quote:Original post by ZahlmanThe map. (Sets are for when you don't need to look things up, just keep them unique according to a "key" that's already embedded in the object". Pull out the name, and just make the "model" be a *wrapped* pointer (typically an already existing smart pointer, such as boost::shared_ptr) to the mesh data.That sounds nice. Thank you for the quick reply.Quote:Original post by ZahlmanAlso, be aware that "list" typically implies a *linked* list; the more general term is "container" (for all of these things) or "sequence" (for those which are ordered, rather than being sorted or providing a key-lookup).That is pretty good to know, never knew that distinction so I just stated them all as lists, I'll make sure to make the proper distinctions next time.   