Wednesday, March 17, 2010

Lists in C# and RemoveAll

So there i am last night, working diligently on the Roundline class. A lovely thing, though i really need to rewrite it's simplified functionality. Well that was sort of what i was doing. Adding in more controls etc.

I am going to use variable width lines for one of my smart bombs for the new shooter. This should look great if i can possibly do it. Adding in the variable width functionality is also priceless as far as adding in Tech to my rather small tech that i use for writing my games. Gameplay shouldn't need tech, but eye candy does.

So all i wanted to do was attach a bunch of lines to each smart bomb explosion. simple enough, but then they need to all die at the correct time. so i added in an ID to the line class. I thought that removal from a list would be so easy. Just for Each loop thru the list and remove them as i go. This is not so easy, oooh no! So upon research on the web i found Removeall. This is exactly what i needed, then a single command would allow me to remove all the list itmes that were corresponding to my ID. Well what a pain. Yep, i have to say that it took me an hour of reading and trying to get the SINGLE line of code to compile. though once it did, it worked a treat.

So lists... hmm,. I usually use arrays for everything and control numbers of stuff etc with Defines. I never ever make stuff grow and shrink. I have seen the horrors this does to memory fragmentation etc. I also know that allocating and deallocating memory is soo freakin slow. So i don't do it. But it seems like i need to learn lists. Just so i know what i am talking about.

BTW: my problems with messing badly with memory come from 26 years of experience, most on machine that had a fraction of the memory of that handy usb pen drive you have on your key ring.

laters

No comments:

Post a Comment