Skip to content
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

Remove p/invoke to RtlMoveMemory, cleanup caller #42749

Merged
merged 1 commit into from
Sep 27, 2020

Conversation

GrabYourPitchforks
Copy link
Member

Two code cleanup changes:

  1. Remove call to RtlMoveMemory, which is getting flagged by Semmle as prohibited. I think this usage is fine, but easier to remove the call site than to fight the tool. The p/invoke signature is incorrect anyway.

  2. Cleanup call site to use raw pointers and to call the existing framework-provided MemoryCopy routine. Note: MemoryCopy takes src before dest in the arguments list.

@ghost
Copy link

ghost commented Sep 25, 2020

Tagging subscribers to this area: @safern, @tannergooding, @jeffhandley
See info in area-owners.md if you want to be subscribed.

@GrabYourPitchforks
Copy link
Member Author

This does not require backporting to 5.0. It's just to make the tools happy for the future. :)

@tannergooding
Copy link
Member

Just wondering, any perf numbers showing increase/decrease?


offsetSrc += sourceData.Stride;
offsetDest += targetData.Stride;
Buffer.MemoryCopy(srcPtr, destPtr, bytesToCopyEachIter, bytesToCopyEachIter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Buffer.MemoryCopy rather than Span.CopyTo?
Also, why copy by row rather than just the entire bitmap at once (which I would imagine has higher throughput)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Buffer.MemoryCopy because I'm already dealing with raw pointers, so may as well use the pointer-based APIs. Converting them to span would introduce artificial complexity for no benefit. It doesn't make the code "safe", for instance.

Copy by row because the source and the destination might have different stride lengths.

Copy link
Member Author

@GrabYourPitchforks GrabYourPitchforks Sep 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, if the destination stride length is shorter than the source stride length, the copy will still "succeed". Though subsequent row copies might overwrite previous row copies, and I don't know what happens to the data beyond the last row of the dest. Hence some of my nervousness around trying to infer what an appropriate "actual dest length" parameter would be, so I'm continuing to say "eh, just assume the dest is large enough" - which matches what the original code did. I'm not trying to fix any bugs that might exist in this code, just bring the code into compliance.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy by row because the source and the destination might have different stride lengths.

Ah, I didn't realize that this supported copying a subset of the original bitmap; that makes sense.

@GrabYourPitchforks
Copy link
Member Author

I don't have perf numbers for this change. This was a code cleanup / compliance change, not a perf change. Though my gut tells me there will be increased throughput since we're no longer relying on the p/invoke marshaler every iteration of the loop.

@jkotas jkotas merged commit a8b793c into dotnet:master Sep 27, 2020
@GrabYourPitchforks GrabYourPitchforks deleted the icon_rtlcpymem branch September 28, 2020 17:50
Copy link
Member

@safern safern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants