New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-9578] Data.withUnsafeBytes(_:) passes pointer pointing copied memory to closure on macOS #3566
Comments
Interestingly, while I don't see the same pointer in both places, I do see successive uses of
I'm not quite sure what to make of that. Maybe cc @phausler |
“test” is small enough to be represented on the stack: so each call takes stack memory locations to pass into the closure (since the bytes are not valid past the call of the block) |
This issue breaks code that depends on behavior "Immutable |
That is correct, it was technically the case before but was not commonly enforced (there were some subclasses of NSData that when bridged could do something similar). Now we have a more common case that has that behavior. This is almost the same change that happened to String when it gains the "smol" implementation. It is worth noting that the cut-off for the byte pointer in the "smol" Data varies per architecture. If the payload can fit into the size of two pointers minus the storage for the length and the storage for the discriminator of the storage we opt for a non-heap implementation of Data. |
Closing this, then, since it's intended behavior and not indicative of a performance problem. |
I confirmed that this issue occurs only when |
Environment
swift-5.0-DEVELOPMENT-SNAPSHOT-2018-12-25-a
on macOSAdditional Detail from JIRA
md5: d854dde68a3c2dbf907f3d8b194f3568
Issue Description:
The
pointerValue
held byData
and thepointerValue
ofUnsafePointer
passed toData.withUnsafeBytes(_:)
are different on macOS.It seems that unnecessary memory copy is occurring.
This issue does not happen on Linux.
The text was updated successfully, but these errors were encountered: