Better Than a Link List?

Started by
1 comment, last by banter 23 years, 3 months ago
Although I refer only to an animation sequence, this technique can be applied to most game data. When creating tools to develop animation sequences it makes since to use linked lists. The user will constantly add and remove frames from the sequence. Frames are not added to the sequence while the game is running. I propose that the sequence be stored as an array. For example: [x, y coord; duration][x, y coord; duration]...[0, 0 coord; 0] // A frame of zero duration is illogical so it is used to represent the end of the sequence (null terminated so to speak). The sequence data can be read from the file all at once. Only a pointer to the head and a pointer or index to the current frame needs to be saved. This saves memory (no pointer to next node on each frame) and could be more efficient. The disadvantage is that memory will become fragmented from allocing and freeing different sized sequences. In a link list implementation all the nodes are the same size. When a sequence is freed another sequence''s frames will fit into the same spaces in memory. I''d appreciate comments and suggestions on this technique.
Advertisement
Your real concern is runtime performance and effenciency, not edit time. Using an array for runtime will use much less memory, the memory you do use will be contiguous and thus cache better and load times will be a bit faster link you mentioned.

I would suggest looking at STL Vectors. They are implemented internally as arrays but are smart about editing and do not continuously dealloc and alloc the array.

--Rick
TribesPlayers.com
Yes, I second using STL. I''ve recently converted all my code to use them. They are fast and easy to use. And the fact that a std::vector can be dynamically added and removed from is awesome. (one of the main reasons to use a link list). Of course there is std::list also (among tons of others).


This topic is closed to new replies.

Advertisement