Linked List VS Controlled Array

Started by
2 comments, last by Rob Loach 21 years, 4 months ago
What''s the difference between using a Linked List, and a controlled array? I''m using this to make sprites. Right now I am using a controlled dynamic array to support enemies on the screen and am exploring other options. I just don''t know why you would use a linked list if you could just use a controlled dynamic array.... Any ideas? Thanks alot, - Rob Loach OverTech Technologies ----------- "Life moves pretty fast. If you don''t stop and look around once in awhile, you could miss it." - Ferris Bueller
Rob Loach [Website] [Projects] [Contact]
Advertisement
I use a simple linked list for objects that don''t need to be referenced by index. All you can do is traverse it form begin to end and get the object it points to. Very fast and only a couple lines of code.
Linked lists have certain advantages over arrays. Increasing the size of an array is a slow operation, and to insert an element in a random position of an array requires you to shuffle, on average, n/2 data. With linked lists, both of these operations are trivial.

Of course, arrays have advantages over linked lists, as well: Random access springs to mind, and in certain situations, dynamic memory allocation may be too slow to be appropriate, and it is better to use a preallocated array (which, of course, requires you to know ahead of time how large it has to be).

(I hope my answer is pertinent to your question; I''m not entirely sure what you mean by ''controlled array''.)
I think in terms of an game, you would want to use a controlled array inside of a wrapper class. For games, there is virtually no reason why the objects would need to be in a particular order. You only need to be able to reference an object by a handle, which can be assigned at run-type (couldn''t spell dynamically)

As a point of curiosity, does anyone know how the class works in terms of speed? Would it be practical to use it for a game? I''m currently using it for a console game, but a more intensive one might bog down too much...

This topic is closed to new replies.

Advertisement