piku wrote:defsdoor wrote:Doubly linked lists take up more space (an extra pointer)
The horrors! One extra pointer!

piku wrote:Linked lists are one of those things that after having to rewrite one for every game you make, become second nature. Unfortunately they also become a right pain to have to rewrite for every game.
Which is why I now use C++ and the STL. vector<enemy *> enemyList; is just 100%* easier to do.
How about this "radical" alternative approach?
Write your own and then stuff it into a code library. Thereby simultaneously gaining the advantages of both approaches at the same time.
Create a library - "MyLib" - and then include it into each project. Then "roll your own" routines and anything you write that's got some useful "code reuse" to it that you might need it again, add it to the library.
Next time you need that linked list, just include it from your code library.
As you go from game to game, the library builds up and becomes a comprehensive "game library" of useful routines. Eventualy, even a sort of "game engine".
But it's all your own code and you can make it work in whatever way you want it to work. You can dive in and add more and refine it at any time.
It'll end up just as handy as the STL but a lot more "game specific" - as there's no reason why you can't throw in, say, generic "physics" routine into the code library (well, the laws of physics don't change very often, do they? Certainly "reuse value" there) or a "pixel shatter" routine or "sprite" routines or whatever else you fancy throwing in there - and, also, where the STL might not favour performance too much (they usually aren't written or designed with the high performance requirements of games in mind), your own library can be happily written with a "need for speed" attitude.
I call it "the Tony Crowther approach" (in honour of the fastest programmer in the West, who reportedly managed such uncanny speeds because he just gutted out the innards of his last game and transplanted them into the next all the time).
Conceivably, though this approach is slow starting, once a comprehensive little library is created, you should actually start accelerating up all the time until using the STL seems like the slow, stupid approach.
Another neat idea in the composition of your "game library" is to actually create it in two flavours - "debug" and "release" - where, basically, the only difference is that you wrap debugging code and asserts and what-not in "'#ifdef" constructs, according to some "debug" define. Compile once with and once without to get the two flavours. Develop with the "debug" version and test the code to destruction. If it passes the test then compile it against the "release" instead (which omits all the debugging code and unnecessary "checks" for improved performance. Logically, if your game passes the "debug" test bug-free then it'll run just as bug-free with the "release" but a little faster because it doesn't bother with all the debugging tests and "checks", which the game has already proved it has passed with the "debug" version).
All the advantages and routines of any STL (and, likely, a lot more besides) while all of it is your own code - written how you like it - and perfectly available for adding to, refining and reusing as much as you like.
Basically, every time you invent a wheel, store it away in the library. Then there's no need for you to ever "reinvent the wheel" again. Just go get it from the library.
But every wheel in there you invented, so it's all put together in exactly the way you like it and perfectly open to amend, refinement and anything else you might fancy doing (e.g. need one of your "physics" routines but the gravity code isn't necessary for this game as it's all in space? Fine, grab the routine, strip out the gravity code and then add it back into the library as additional "PhysicsWithoutGravity" functions. Let's see an STL do that kind of thing, eh?

).
All you need do is start your next project with an empty library - "MyLib" - and then keep moving that library from game to game, as you write more games. When you need something you've already done in the previous game, just include it from the library. When you write something new that would be useful in other games, don't pop it into your game code directly but put it into the library and then include it back out of the library (and then it's sitting there in the library to be "reused" the next time around).
It's just a little extra bit of maintenance - but not a big deal, really, in the grand scheme of things - and as you write more games, you'll soon end up with a pretty kick arse library of game routines that should allow you to put together games at an incredible pace (making the use of the STL seem like the bad idea in comparison).
Programmers do tend to often have this thing of reinventing the wheel all the time. But that's why libraries were invented.
All the STL is, after all, is exactly just the same kind of code library but someone else put it together for you (but it's very generic and not at all "game specific").
There's no real reason why you can't just do that yourself.

"Words ought to be a little wild - for they are assaults of thought on the unthinking."
- John Maynard Keynes