How bad is this really?? How much better of an idea is it to store a pointer as opposed to the class itself?
How bad is this really?? How much better of an idea is it to store a pointer as opposed to the class itself?
It's an extremely bad idea to do it both ways, because the vector could become too difficult to keep trace of as your code grows! And if there is a nasty bug preventing your game from functioning correctly, you could end up with a very hard-to-find bug or two.
It sounds to me that you need to look into 'Design Patterns'. These provide advanced methods for structuring your data in a safe way, and managing how many, as well as when instances of your class will be spawned. Research 'singleton' and 'factory' as the most popular examples.
I'm not so sure I need a Class Factory for the purpose intended here. I have simply created a Class to contain the parts of the body of the components of the .x file as a temporary means of storage
skipping most of all the code............The components will soon after be dissected and stored in containers held by the DX interfaces......... I did look into factories before hand, but I disregarded. I believe factories would pertain more to a large scale creation of objects............yes/no??Code:class CSceneObject { public: string name; CSeneObject(string str) : name(str) {}; vector<string> vBody; }; class other { private: vector<CSceneObject> vObjects; };
Last edited by WingedPanther; 07-04-2009 at 07:28 AM. Reason: add code tags (the # button)
It depends a LOT on the class. Vectors occassionally need to reallocate their memory, which means moving ALL contents to the new, larger, internal array. If you have a class with a lot of data, this can make resizing the vector very expensive unless you use pointers to the class in your vector. Unless you're using some form of smart pointer, however, you now have the potential for memory leaks.
CodeCall Blog | CodeCall Wiki | Shareware
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
But reallocation doesn't occur every time you add a new element to the vector??
I think my hang up here is I don't want an array of anything like pointer[i]. I want to use some form of unique identifier, a name, a UUID. The way I set it up above is good for me but I'm already seeing that it takes for ever to process.
It depends on your implementation, the particular class, etc. Also, are you storing a copy of an existing class, a reference to an existing class, etc? If the copy constructor is having issues, that would explain a LOT.
CodeCall Blog | CodeCall Wiki | Shareware
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog
that's about it.........Code:vObjects.push_back(CSceneObject(vMeshFile.front())); while(!(vMeshFile.front().find("}") == 1)) { vObjects.back().vBody.push_back(vMeshFile.front()); vMeshFile.erase(vMeshFile.begin()); if(vMeshFile.size() == 1) return false; }
I should probably stop cutting and pasting everything from and to containers. It would probably be best to set pointers to various parts of the file(index it) and then copy the appropriate sections to the appropriate containers within the DX interfaces........
Last edited by Buttacup; 07-04-2009 at 04:48 PM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum