[.net] vb.net Redim Preserve Efficientcy?

Started by
5 comments, last by capn_midnight 18 years, 8 months ago
how efficient is it to redim preserve to free up memory in an array compared to just letting the item waste memory? anybody have any tips?
-----------------www.stevemata.com
Advertisement
I presume you're trying to grow an array that turned out to be too small for your needs. Arrays are meant to be fixed in size, don't let VB fool you. If you need a growable array, use an ArrayList or any of the other System.Collections.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

I suppose it depends on the number of array elements and the memory consumption of each element.
well the majority of the time the array is fixed, but periodicaly i need to add or remove a ship.

---------------------------------------------------

Square Dance Studios
-----------------www.stevemata.com
Don't Redim each time you add a ship, Redim a big chunk like 100 more than you need, then when you fill that array Redim it to be 100 larger. This will work a lot faster.
Quote:Original post by Stru
Don't Redim each time you add a ship, Redim a big chunk like 100 more than you need, then when you fill that array Redim it to be 100 larger. This will work a lot faster.


Or better yet, use System.Collections.ArrayList, since it will already do that for you.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
whenever an ArrayList runs out of room, it doubles in size.

[Formerly "capn_midnight". See some of my projects. Find me on twitter tumblr G+ Github.]

This topic is closed to new replies.

Advertisement