how to copy an array?

BlitzMax Forums/BlitzMax Beginners Area/how to copy an array?

Hi folks,

how can I copy an multidimensional array? I just found "slices", but that just works on 1d-arrays...

If its an array of one of the basic types (int,float, etc) you should be able to use MemCopy.

You can't just use a single memcopy.

For each dimension in the array you have separate memory spaces. The first dimension is all in one memory space. But then each array pointed to by the first array has its own memory space.

You have to write a loop to do the copy in parts.

grable is correct, just use memcopy...

' create and fill source array
Local array:Int[10,10]
Local i:Int,n:Int,c:Int
For i=0 Until 10
	For n=0 Until 10
		c:+1
		array[i,n] = c
	Next
Next

' create new array and copy contents of the source array into it
Local copy:Int[10,10]
MemCopy(copy,array,SizeOf(array))

' prove contents are correct
Local l$
For i=0 Until 10
	For n=0 Until 10
		l$:+copy[i,n]+"  "
	Next
	l$:+"~n"
Next
Print l