Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
NB_
Roku Guru

Re: array pass by value?

"Komag" wrote:
I realize this is years old, but I just can't believe this isn't an official Function by now! I use TheEndless' ShallowCopy() Function now in several key places to copy Associative Arrays of various depths where I don't want references but actual new copies.

You want a deep copy of (acyclic) structure of simple types/arrays/AAs, just use
newCopy = parseJson(formatJson(myData))

You want other/reference types in the mix, use variation of the above `shallowCopy`. Deep copy should be hard, when you do it you should know it is expensive. To that, some "magic" function will be misleading you in thinking it's easy/cheap, when behind the scene it is expensive. I see this confusion all the time with the RSG field dot-access, then complains "why is my code/Roku slow".
0 Kudos
Komag
Roku Guru

Re: array pass by value?

Hmm, I'm not experienced in programming and haven't seen enough to judge the wisdom of making deep copy easy or hard. I do try to use it sparingly, at times when performance isn't as important (such as when loading the game - as opposed to during game-play).
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.