Clear an Array?

BlitzMax Forums/BlitzMax Programming/Clear an Array?

Tachyon(Posted 2006) [#1]
Sorry for the rudimentary post, but I couldn't find the answer on my own. :(

I have a multi-dimensional array of TImages. When I need to clear the old contents and load new images into it, I've just been doing it via a New command. Is there a better way I should be doing it (something like a "FlushArray" method or somthing like that?)

I should mention that I have to clear the old images out first because sometimes the new set going into the array doesn't use all the cells, so I save memory by clearing the cells first.


Helios(Posted 2006) [#2]
I'm not sure if BlitzMax's arrays are stored in unified memory, but if it is you might be able to get away with a memclear.

MemClear(Byte Ptr(myArray), size);



H&K(Posted 2006) [#3]
If you just point the cell to a TImage it doesnt create a copy of the image, just changes the pointer to were the image is.

If the image isnt refferenced anywhere else, then just pointing the array cell to the new image makes the GC destroy the old one.

If you point a cell to NULL, then the above happens, but the array is the same size. (ie the same number of pointers)


Tachyon(Posted 2006) [#4]
H&K: exactly. I just did a test and figured this out after checking the memory usage.

Thanks for the replies gentlemen.