Forum Discussion

rokenbuzz's avatar
rokenbuzz
Binge Watcher
6 years ago

ifArray.Append needs start_pos and length parameters

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

4 Replies

    • rokenbuzz's avatar
      rokenbuzz
      Binge Watcher

      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?

      • RokuKC's avatar
        RokuKC
        Roku Employee

        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.