• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

OFFICIAL Copy on Write Behaviour for arrays - possible removing it?

FredFredrickson

Artist, designer, & developer
GMC Elder
Well, I just tried disabling the new setting in my project, and it broke literally everything that had to do with arrays, lol.

So let me get this straight - whenever I pass an array into a function, the old behavior was to silently make a copy of the array - and the new behavior is to just pass a reference to the original array?

That seems... weird to me. Because that's not how regular variables work when you do the same.

The solution then (aside from just leaving the old behavior on) is to use array_copy() in all of my array-handling scripts. But then I need to do a length check on top of all that. Is there a simpler way to copy arrays than that now?
 
Last edited:

Arraveci

Member
I may be wrong, but I'm finding that array copy doesn't function as I thought it would for multiple dimensions- It seems to just copy the reference to the sub array at the index rather than the array itself, meaning that when I later change one array I'm changing any which also copied from the same source array...
 

chamaeleon

Member
I may be wrong, but I'm finding that array copy doesn't function as I thought it would for multiple dimensions- It seems to just copy the reference to the sub array at the index rather than the array itself, meaning that when I later change one array I'm changing any which also copied from the same source array...
There are no multi dimensional arrays in GMS anymore, only one dimensional, and copying the values stored from one to another will not perform copying of arrays that may be stored in some position in the array being copied. Write utility functions of your own that has the exact semantics require for your use cases.
 

Arraveci

Member
It was just arrays with arrays in them, no complicated datatypes, so I thought the general array copy could handle that at least, but yeah I wrote a quick script which does copy all the indices even if they're arrays, however deep they go. I just wish it had been stated in the manual, but maybe I missed it.
 

chamaeleon

Member
It was just arrays with arrays in them, no complicated datatypes, so I thought the general array copy could handle that at least, but yeah I wrote a quick script which does copy all the indices even if they're arrays, however deep they go. I just wish it had been stated in the manual, but maybe I missed it.
I could probably agree on that it perhaps should be mentioned in both or either of array_copy() manual page and Multi-Dimensional Arrays array reference section. Perhaps you will find a receptive ear to this at YYG if you file a request.
 

drandula

Member
Yeah, array can have references to other arrays to create illusion of multidimensional array, and behaves mostly like one.
But this means if you use array_copy, it only copies references to other arrays from first array.
 
Top