View Poll Results: Arrays of Vectors?

Voters
28. You may not vote on this poll
  • array

    3 10.71%
  • vector

    6 21.43%
  • depends on situation...

    19 67.86%

Thread: arrays or vectors

  1. #1
    Geo Geo Geo-Fry
    Join Date
    Feb 2003
    Posts
    116

    Post 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

  2. #2
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    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.

  3. #3
    Registered User Moni's Avatar
    Join Date
    Oct 2002
    Location
    Dhaka, Bangladesh.
    Posts
    104
    Offcourse this depends on situations!
    I use arrays normally as C programs.
    And in C++ programs I like vector as the code remain pure C++.
    But it's just my habit !!!
    We all are the components of a huge program...... the programmer is always debugging us with His debugger.

  4. #4
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    I think it would've been cool to write the stl vector class. I do admit vectors are very useful.

  5. #5
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    http://www.parashift.com/c++-faq-lit....html#faq-34.1
    I use vectors unless i'm coding time-critical seconds, or using an interface which only supports arrays (e.g. winsock or win32 api)

  6. #6
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    What do you mean using an interface that only supports arrays? How does win32 only support using arrays?

  7. #7
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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
    Eh? Are Swedes that cool, huh?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  8. #8
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    the underlying structure in the STL are linked lists (for vectors, maps, lists, sets, etc....). handy to use, but slow when every little cycle counts. (ruins the cache 'predictions')

    i prefer making my own dynamic structures that reallocate into new arrays, keeping everything consecutive in memory. although this does make 'expanding' slower, run time access is faster.

    its really not a huge difference but this programmer from EA gave a seminar at my school and said "stay away from the STL when game programming..."

  9. #9
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    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.
    FAQ

    "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.

  10. #10
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    Short thread on the topic.

    gg

  11. #11
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    I have never used a vector<>

  12. #12
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    I usually prefer vectors, they are just so much easier and flexible than arrays imo.

    I do use arrays though for small constant containers. Also if I don't feel like digging out my matrix class, I use arrays for two-dimensional structures which vectors are a pain to use.

  13. #13
    Registered User
    Join Date
    Jan 2003
    Posts
    37
    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.

  14. #14
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    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.

  15. #15
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Vectors versus normal arrays
    By _izua_ in forum C++ Programming
    Replies: 10
    Last Post: 08-12-2007, 01:59 AM
  2. Arrays vs Vectors
    By swgh in forum C++ Programming
    Replies: 5
    Last Post: 05-04-2006, 02:06 AM
  3. vectors vs c style arrays
    By markucd in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2006, 11:11 AM
  4. byte arrays & vectors
    By kasun in forum C++ Programming
    Replies: 1
    Last Post: 02-29-2004, 09:10 AM
  5. arrays and vectors
    By volk in forum C++ Programming
    Replies: 1
    Last Post: 03-30-2003, 03:45 PM