View Poll Results: Arrays of Vectors?

Voters

28. You may not vote on this poll

array

310.71%

vector

621.43%

depends on situation...

1967.86%

arrays or vectors

This is a discussion on arrays or vectors within the C++ Programming forums, part of the General Programming Boards category; which do u prefer? the reason i ask is that most people on these boards seem to be using arrays ...

arrays or vectors

which do u prefer? the reason i ask is that most people on these boards seem to be using arrays and not vectors, but the tutorial im using (from cplus.about.com) really seems to downplay the use of arrays and makes it seem like vectors are much better

"You can lead a man to Congress, but you can't make him think."
"The Grand Old Duke of York
-He had ten thousand men.
-His case comes up next week."
"Roses are red, violets are blue, I'm schizophrenic, and so am I."
"A computer once beat me at chess, but it was no match for me at kick boxing."
"More and more of our imports are coming from overseas."
--George W. Bush
"If it weren't for electricity, we'd all be wacthing TV by candlelight."
--George W. Bush

This isn't a valid poll, of course it depends on the situation. Vectors are not arrays! They are high level data structures that act like arrays (they even have the [] operator overloaded so you can access them like arrays) but they are definitely not arrays. They are most useful when you want to put a new value onto the list, and of course most people find them pretty nifty! But even when you just want a list of items you may not want a vector, rather you might want a stack, queue, or create your own linked list structures.

I prefer to make my own structures like that. I see no use to make a high level class for a simple array.
I've made a linked list template which I'm using in most programs I need a list in, and it's working great.

Silvercord
I'm not really from Sweden, but everyone seems to think people from Sweden are cool, so I'm just pretending to be from Sweden so more people will like me

You are right in saying that there are times when I'd rather use a stack or queue for my container, but I can't think of a time I'd rather use an array over a vector. I know that's just due to my laziness, but I feel that I am competant enough with arrays that I don't have to prove to others that I know how to use them. Vectors are so useful to me because they afford me many of the pros of arrays without making me worry about the cons. resize() is so much nicer than having to worry about how much to new or delete.

I must admit though that I am not a professional programmer, so I rarely worry about subtle performance differences. I'm sure that arrays are better on memory and processor speed, but their a pain to use in my opinion.

"The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

"If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

Originally posted by spidereen What do ye mean by vectors. Are ye talking about linked list.
Isn't an array just like a fixed pointer and indexing into it is like pointer arithmetic.

array[10]

&array + 10

Maybe I am all wrong on this.

vectors are ADT's from the standard template library. at base level they are linked lists. they are different from arrays because they are dynamic (expandable) and are not necessarilly consecutive in memory. Arrays on the other hand are consectutive in memory and there for can be indexed as in your example.

Originally posted by Perspective vectors are ADT's from the standard template library. at base level they are linked lists. they are different from arrays because they are dynamic (expandable) and are not necessarilly consecutive in memory. Arrays on the other hand are consectutive in memory and there for can be indexed as in your example.

No, actually you're wrong here. A vector is usually implemented as an array, NOT a linked list. they "expand" by reallocating and/or reserving memory. This I am sure of.

Also, I may be mistaken in this last part as I don't usually use the STL, but I believe it may even be required that a vector occupies consecutive space in memory.