Dynamic Array Management
I want to create a dynamic Array in my App like this:
CMyObject* objBuffer;
// in the init function
objBuffer = new CMyObject[value];
my problem is in this case that my buffer has to grow while the programm. So how can I now get a new Buffer which contains all old objects and 1 additional object like this:
CMyObject* newObjBuffer;
newObjBuffer = CMyObject[value+1];
how can I now copy the Data from the objBuffer into the newObjBuffer.
Or is there a completely different solution for such a problem?
Thank you
Better use
Check out the vector specs for a complete overview of the class. Note that there are other alternatives such as std::list etc., but std::vectors''s very good place to start.
Hope this helps,
Crispy
std::vector
instead: #include <vector>void foo(){ std::vector<CMyObject*>objBuffer; //add stuff CMyObject* a; objBuffer.push_back(a); }
Check out the vector specs for a complete overview of the class. Note that there are other alternatives such as std::list etc., but std::vectors''s very good place to start.
Hope this helps,
Crispy
sound''s like you could use a linked list.
you can utilize C++'' STL for this, do a web search
how to use ie std::list.
If you''re interested to implement one yourself, for
learning, just search for linked list. there are hundreds
of example implementations on the web.
wenn''s hilft, kannst du (zumindest) mir auch in deiner muttersprache fragen stellen
Hey cool!
Naja auf jedenfall hab schon mal selbst so ne Linked List gemacht um unter Direct3D Texturen zu verwalten des hat ganz gut geklappt!
Bloß hab ich jetzt in meinem Spiel das D3D X Fileformat verwertet eine liked list deren elemente wiederum liked lists sind. Naja und da ist dann mit meiner Technik ein fehler aufgetreten.
Sollte ich mir ein eigenes liked list management erstellen oder reicht std::vector??
Naja auf jedenfall hab schon mal selbst so ne Linked List gemacht um unter Direct3D Texturen zu verwalten des hat ganz gut geklappt!
Bloß hab ich jetzt in meinem Spiel das D3D X Fileformat verwertet eine liked list deren elemente wiederum liked lists sind. Naja und da ist dann mit meiner Technik ein fehler aufgetreten.
Sollte ich mir ein eigenes liked list management erstellen oder reicht std::vector??
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement