<FromGitter>
<mattrberry> What's the fastest way to copy values between two arrays?
<FromGitter>
<mattrberry> Specifically to copy a section of one array to a section of another array
<FromGitter>
<mattrberry> Could be a Slice too, doesn't matter to me
yukai has quit [Ping timeout: 264 seconds]
<FromGitter>
<HertzDevil> `Array#[]=`
<FromGitter>
<HertzDevil> if the source and destination types are the same it seems the method will ultimately be implemented by memcpy/memmove intrinsics
<FromGitter>
<mattrberry> What if I need to effectively copy a subrange of one array to another array at the same index? Still the same?
<FromGitter>
<mattrberry> Okay, I'll give that a shot. Hopefully not a performance issue
<FromGitter>
<mattrberry> I realized I'm currently using Bytes rather than an array anyway, but I'll just swap to an array
<FromGitter>
<mattrberry> I need to copy 240 byte segments hopefully around 100,000 times per second
<FromGitter>
<mattrberry> :p
<FromGitter>
<christopherzimmerman> What’s the use case?
<FromGitter>
<mattrberry> gba emulator
<FromGitter>
<mattrberry> I don't *really* need that and can do stuff a different way, but I just thought it'd be fun to do it that way if I could copy values fast though :)
<FromGitter>
<christopherzimmerman> If you have to use an array, it’s probably going to be faster to just use the underlying pointer rather than interact with the array itself.
<FromGitter>
<mattrberry> Yeah I kinda figured that'd be the case
<FromGitter>
<christopherzimmerman> So just an array of UInt8 and need to copy 240 elements at once? Does that ever change?
<FromGitter>
<mattrberry> Sorry, I misspoke slightly. It's a UInt8 array (or Bytes) and I need to copy 480 bytes ~10000 times per second without it being any source of overhead. It's really a hyper-specific usecase that I've already done a different way so it's a non-issue, I was just curious what the fastest way to do this copy would be in crystal :)
<FromGitter>
<HertzDevil> as long as it's memcpy/memmove it's probably as fast as you can get in crystal (in release mode)
<FromGitter>
<HertzDevil> unless you start caring about cache misses