Arrays vs Vectors vs Lists for particle rendering?

This is a discussion on Arrays vs Vectors vs Lists for particle rendering? within the Game Programming forums, part of the General Programming Boards category; I was just wondering is there was a significant tradeoff to using a vector or list rather than an array ...

  1. #1
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901

    Arrays vs Vectors vs Lists for particle rendering?

    I was just wondering is there was a significant tradeoff to using a vector or list rather than an array for holding things like small sized particle structures and calling them each frame. I'm simulating a simple rain rain simulation that changes the attributes of the raindrop structure each frame as it falls. Would there be a tradeoff.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    I think slists should do the trick since I will simply be going through each particle in order each frame and since the number of particles is set at the beginning, then I won't have to worry about insertions or deletions. Though I think a vector or a list would do the same if insertions or deletions are not involved after the instantiation right?

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,659
    When in doubt, pick a meaningful abstraction which allows you to mess about with the implementation without affecting the rest of the code.

    Or pick the data structure which makes most logical sense for the problem - ie, easiest to implement your solution, given a set of plausible alternatives. Trying to second-guess actual performance trade-offs in advance is a waste of time.

    When the program is done, then you profile it to find out where the real issues are.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    When it comes to particles I would use a vector but it all depends on how your system works. If the particles are a member of the class that handles an explosion and it is responsible for rendering itself then an array would suffice. The array would be populated as soon as the explosion was created and since no new particles would ever be added there would be no need for adding, insertion, searching, etc, etc.

    But if your particle system is one in which the particles are added to a master particle list and then the list manager class either renders them or hands off the rendering to a master render class then a vector would make life much easier.

    In short: use the right tool for the job.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. lists (arrays, vectors, etc.) of different types
    By Mostly Harmless in forum C++ Programming
    Replies: 4
    Last Post: 11-21-2008, 09:46 PM
  2. vectors vs c style arrays
    By markucd in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2006, 11:11 AM
  3. Arrays Vs Linked Lists
    By ianbd in forum C++ Programming
    Replies: 3
    Last Post: 08-31-2005, 08:41 AM
  4. From Python's Linked Lists to Dynamic Arrays
    By hexbox in forum C Programming
    Replies: 3
    Last Post: 01-26-2005, 02:14 PM
  5. arrays or vectors
    By Geo-Fry in forum C++ Programming
    Replies: 26
    Last Post: 04-17-2003, 07:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21