It's undefined behaviour. It might work, either by design or accident, or it could be really slow or stop working in the next OS update or hardware revision. Just avoid it.
if it works by design it's quite pity to see the man-years(?) of hardware designers cumulative time wasted for a feature that they considered needed and that we end up not using, because it might not work in the future!
UnsafeMutableRawPointer.copyMemory(from:byteCount:) simply forwards its parameters to memmove as (essentially) memmove(baseAddress, from, byteCount).
Hi Karl,
For the time being I'm not concerned with the data representation of my packet structures. I just need to encode my packets into Data and decode them into the same typealias or struct on the receiving system. I will eventually need to be concerned with the representation, but for now I can assume the receiving system will be of the same type as the sending system. I see some other posts from telecommunication developers trying to use Swift, but they may have match particular data layouts. I only added the "packed" attribute to trade off some CPU time for communication bandwidth. I'm not trying to use unaligned pointers, but I was expecting the Swift compiler to generate bit shifting and masking as the Obj C compiler does. I can build up packets using the data.append and avoid variable length arrays in my structs.
Thanks,
Bob Rice
consider MessagePack or a similar beast. it's like JSON, but binary, smaller and quicker.
The only difference is that copyMemory allows overlapping memory regions. It has memmove semantics.