• Advertisement

Archived

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

Dynamic Array Management

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

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

Share this post


Link to post
Share on other sites
Advertisement
Better use 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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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??

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

du hast post.

- unshaven

Share this post


Link to post
Share on other sites

  • Advertisement