I'm finding a lack of functions to move raw bytes around in arrays. I can write my own brightscript functions but they are insanely slow compared to if these are implemented in the underlying component architecture.
For example, roByteArray has ifArray.Append which is blazing fast compared to any equivalent I can write in brightscript. That's great, but it has no start_pos and length. So if I want to copy the middle 1000 bytes out of an roByteArray of 8000, without looping in my own brightscript, what can I do?
ifByteArray.AppendFile and ifByteArray.ReadFile have start_pos and length parameters, so these could be used as a hackish work-around, writing to file and reading back to an roByteArray to accomplish this. I had some hope, figuring tmp:/ must just be memory anyway, but I'm profiling ifArray.Append and ifByteArray.AppendFile (with no start_pos and length params) and finding it's 10 times slower to use the file.
Am I missing some basic array copy methods?
As a quick fix, having ifArray.Append with start_pos and length parameters would help tremendously.
rokenbuzz
I found this thread from 10 years ago asking for the same thing and also pointing out file I/O as a possible work around.
https://community.roku.com/t5/Roku-Developer-Program/New-Telnet-Functions/td-p/111837/page/4
After a decade there is still no method for copying bytes.
Is it time?
It's been a long time but I still would find this ifArray function extremely useful:
Append(source_array As Object, source_index as Integer, dest_index as Integer, length as Integer)
to easily copy bytes super fast.
Please?
Request noted, and seems very reasonable to me.
For roByteArray, I don't see an existing solution. However I'll guess that the best solution currently may be to use roByteArray.ToHexString(), then use string.Mid(startIndex, numChars) (where startIndex and numChars should both be multiples of 2) to pull out the desired segments and compose them together as needed, then use roByteArray.FromHexString() on that.
For roArray, it looks like there might be an existing API that would help, although for some reason it is not documented currently. I'll look into that to see if the SDK docs can be updated and if so post an update on that here if/when I can.
Yes, I recall experimenting and profiling several clever solutions, such as using roByteArray.ToHexString() as you describe, or at least something similar. It's been a while. But in the end performance wasn't great.
Basically what I'm looking for the equivalent to a C memcpy.