Dynamic Array Management

Started by
4 comments, last by Semicolon 21 years, 10 months ago
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
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
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared

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

Thank you!!
That seems to be a very good solution for my prob!
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??

du hast post.

- unshaven

This topic is closed to new replies.

Advertisement