-
Notifications
You must be signed in to change notification settings - Fork 112
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
Make a copy for packet.Payload
instead of slicing
#7
Comments
I wonder if we can unexpose p1.Payload, and have some kind of copy-on-write semantics (just because i think writing into the payload of an unmarshalled packet like this is kind of a rare edge-case) |
I don't think copy-on-write is possible in Go because there's no such thing as a read-only slice. If you call I definitely want the default behavior to be safe. Kind of like how when you pass a buffer to To that end, I would propose having |
👍 on this from me, I am running into this (I can fix it, but I can see why people would be surprised) I added |
In Galène, we use Unmarshal to access the header bits without copying the packet. We essentiallydo this :
Note two things about this code:
The second point is less important, since I could potentially use a second buffer in this case. If you change the semantics of |
When Unmarshalling, the current code slices the input to set
packet.Payload
. This is fast, but we really should make a copy to avoid nasty bugs. For example:You know how performance crazy I can be, but we should
copy
instead of keeping a reference to the data provided toUnmarshal
.The text was updated successfully, but these errors were encountered: