Quote:Original post by synth_cat
Well, thanks for that explanation, deathkrush!
So, I'm curious: If I were to only use resize() to create this array, without any of the dynamic stuff ever being used, what would be the exact advantages over just saying "TRI tris[TRIS_SIZE]?" I ask this because I do not intend to resize my arrays during execution; there are various design reasons why this would be problematic.
vectors store their data on the heap, not on the stack, so you no longer have those arrays taking up space in that precious ~1MB stack space.
Quote:
Is the syntax for accessing a data element of a vector the same as for an array? For example, would this work?
*** Source Snippet Removed ***
Yes.
Also note that you can use vector<TRI> tris(TRI_SIZE); to get the same effect as the first 2 lines.
Quote:
I know I keep asking this question, but can someone tell me at what point it becomes requisite to use these special array-creation methods? Or should I just use vectors for all the arrays I ever make, just to be safe?
I use vectors / other std::containers for just about every array related thing I need to do. I use std::string for all string operations where I can.
Its easier because I dont have to worry about creating, naming and updating "magic" numbers for array sizes. In most stl implementations std::vector will do bounds checking in debug mode which can also be a help.
I think zahlman put it best one time, something like "arrays make sense when the size of the array comes from the program domain ( developing a chess game, the chessboard is *always* 8 x 8 )".