Blitz2D Intermediates: Preserved Redimensional Arrays
by Seth Jeffery (cyberseth)

Preserved Redimensional Arrays

Ever wanted to redimension an array but preserve its contents? Well, you can! With a little crafty type manipulation!


Now think about what we've just done. We've created an array of 101 (0-100) empty POINTERS. Then we have gone through each pointer and set it to point to a new object in the type list. So in effect we have created 101 type objects, 1 for each pointer in the array.

Now what happens if we redimension the array?
(We don't need to say .myvar anymore because we've already declared var as being a type pointer. The same way that if you declare an object as a float# you don't need to use the # after than the first time.)


Have we, indeed? It is true that after redimensioning the array, all our pointers have been set to null. But.. they're just pointers to the type list. We haven't actually deleted any of the objects IN the type list. The only way you can delete a type object is with the DELETE command. So.. They are still there! And we can get them back like so...


Interesting eh? So, if we can redimension an array and still get back all the types that the array was pointing to (and thus all the information) then it is entirely possible to form your own Redim Preserve command...


If you've read all this far and you understand, AND it works, then give yourself a pat on the back. Well done!

- Seth Jeffery (cyberseth)


For a printable copy of this article, please click HERE.


This site is Copyright© 2000-2004, BlitzCoder. All rights reserved.