How to convert from types into an array

BlitzMax Forums/BlitzMax Programming/How to convert from types into an array

Robert Cummings(Posted 2005) [#1]
Hiya,

How do you convert from types to arrays, and is the data still accessible?

Can you also access the fields just the same?

Can I destroy this array, and if so, how?

What if I need to "refresh" the array with contents from types (think of an editor) - will this lead to memory leaks? The Types will be different sizes each time.

Many thanks!


Diablo(Posted 2005) [#2]
I think you mean lists. Types are just like varibles in BMax meaning you can just do this:


hope this helps a little.


Robert Cummings(Posted 2005) [#3]
Thanks - it does. Does wrapping it in my Type cause a performance hit? For example myType(myTypeArray[0]).x verses myTypeArray[0].x, which is possible if I just make my own arrays and copy a list manually?

Also, how do I resize and remove an array once I have it?


Diablo(Posted 2005) [#4]
you can resize using slicing... there should be somthing about it in the docs:
Local a[200]	'initialize a[] to 200 elements
a=a[50..150]	'extract middle 100 elements of a[]
a=a[..50]     	'extract first 50 elements of a[]
a=a[25..]	'extract elements starting from index 25 of a[]
a=a[..]		'copy all elements of a[]
a=a[..200]	'resize a[] to 200 elements

taken from the docs...

to get rid of an array you could just set it to null
myArray = Null


i'm not sure about type casting hinders perforamce IMO i don't think it does.


Robert Cummings(Posted 2005) [#5]
Thank you very much :)


JoshK(Posted 2006) [#6]
How do you remove an element from the middle of an array? Say my array size is 100 and I want to get rid of item 53. How do I do that?


FlameDuck(Posted 2006) [#7]
How do I do that?
It depends on whether you want empty places in your array.

If you do, you just go array[53] = null.

If you don't you need to either:
* Swap it with the last element, and cut the last element off the array.
* "Compact" the array, which usually involves traversing the array, and moving elements down when a null reference is found.
* Use lists instead.