std::vector operator[]

Started by
13 comments, last by Basiror 19 years, 4 months ago
About the smart pointers:
- i am going to need a scene management class in my editor so i can add the deallocation for each object into this class *it stores the root of the scene anyways

to the class hierarchy:
- i just want to keep the possibility but in general i won t need a single cast
- my hierarchy builds on the top of CBaseObject which is the basic representation of everything you can manipulate,create and destroy inside the editor
its pretty similar to the 3dsmax class layout you have got a CNode class and tons of derived classes


about std:vector

just wondering how does std:vector store the objects internally?
stacks or linked lists? or lists of stacks ?
http://www.8ung.at/basiror/theironcross.html
Advertisement
Quote:Original post by Basiror
about std:vector

just wondering how does std:vector store the objects internally?
stacks or linked lists? or lists of stacks ?
As a dynamically allocated array. Nothing more. Whenever you try to add beyond how much size is currently allocated, it will allocate a new memory segment, larger than what you currently have, copy all the current data to the new memory segment, add the new element, and delete [] the old memory. It tends to double the amount of memory it allocates, each time it resizes, so that it doesn't need to reallocate and copy very often.
"We should have a great fewer disputes in the world if words were taken for what they are, the signs of our ideas only, and not for things themselves." - John Locke
Quote:Original post by Basiror
just wondering how does std:vector store the objects internally?
stacks or linked lists? or lists of stacks ?


The internal storage of a vector is guaranteed to be a contiguous unpadded block*. In practice this means that vector uses a single array internally. When the vector grows beyond its capacity a new array is created and the contents of the old array are copied over. You can use resize to avoid unnecessary reallocations.

Enigma

*Well, a few years ago it was "about to be guaranteed", so I guess they must have added it to the standard by now!
Quote:Original post by Enigma
You can use resize to avoid unnecessary reallocations.


Also see reserve, if you don't want all the objects to be initialized immediately.
ok thx

time to move on with the project :)
http://www.8ung.at/basiror/theironcross.html

This topic is closed to new replies.

Advertisement