|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Re: Storing a Class in a Vector
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. |
|
||||
|
Re: Storing a Class in a Vector
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 |
|
||||
|
Re: Storing a Class in a Vector
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. |
|
||||
|
Re: Storing a Class in a Vector
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 |
|
||||
|
Re: Storing a Class in a Vector
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 05:48 PM.. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Tutorial: Starting C# with C# 2008 Express Edition | Jordan | CSharp Tutorials | 20 | 07-27-2009 05:45 AM |
| PHP Objects | chili5 | PHP Tutorials | 5 | 03-24-2009 06:12 PM |
| Java Vectors | chili5 | Java Tutorials | 10 | 02-17-2009 07:55 PM |
| PHP 5 and OOP | Jordan | PHP Tutorials | 11 | 09-22-2008 02:58 AM |
All times are GMT -5. The time now is 06:55 AM.
Amrosama.cc
Arekbulski.cc
Debtboy.cc
Guest.cc
Jaan.cc
James.cc
Mathx.cc
Tsz.cc
Vswe.cc