Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Adding Memory.Pin() to eventually replace Memory.Retain(bool) #17269

Merged
merged 3 commits into from
Mar 28, 2018

Conversation

ahsonkhan
Copy link

@ahsonkhan ahsonkhan commented Mar 27, 2018

Related PR in corefx: dotnet/corefx#28517

cc @KrzysztofCwalina, @jkotas, @davidfowl, @stephentoub, @dotnet/corefxlab-contrib

@davidfowl
Copy link
Member

@ahsonkhan let this change propagate through all of ASP.NET before the removal.

@ahsonkhan
Copy link
Author

ahsonkhan commented Mar 27, 2018

let this change propagate through all of ASP.NET before the removal.

OK. How can I help to get it propagated? Let me know when there will be a dependencies update in ASP.NET.

@davidfowl
Copy link
Member

OK. How can I help to get it propagated? Let me know when there will be a dependencies update in ASP.NET.

We're working on maestro bot integration aspnet/Universe#968

@joshfree
Copy link
Member

We're working on maestro bot integration aspnet/Universe#968

@davidfowl can you push to get the aspnet maestro stuff turned on today? @ahsonkhan should have the API additions in today; and we'd like to merge the removal PR tomorrow...

/// Returns a handle for the array.
/// <param name="pin">If pin is true, the GC will not move the array and hence its address can be taken</param>
/// Creates a handle for the memory.
/// The GC will not move the array until the returned <see cref="MemoryHandle"/>
Copy link
Member

Choose a reason for hiding this comment

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

The doc comment should not talk about arrays. In the OwnedMemory more there might not be an array.

Copy link
Author

@ahsonkhan ahsonkhan Mar 27, 2018

Choose a reason for hiding this comment

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

Agreed. The docs should also mention the possibility of GCHandle.Alloc throwing (An instance with nonprimitive (non-blittable) members cannot be pinned.).

I will address this separately after all the changes are in.

ReadOnlyMemory<object> memory = new object[10];
memory.Pin(); // throws ArgumentException

/// </summary>
public unsafe MemoryHandle Pin()
Copy link
Member

Choose a reason for hiding this comment

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

Do we prefer the whole method to be unsafe, or just the part that does pointer arithmetic?

Copy link
Author

Choose a reason for hiding this comment

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

I kept the changes from Retain minimal. Also, we would end up with two unsafe blocks if we want to make this change (within each condition), which doesn't buy us much. Otherwise, it would be around the entire if block, which is essentially equivalent to it being around the whole method.

@ahsonkhan ahsonkhan merged commit 0578152 into dotnet:master Mar 28, 2018
@ahsonkhan ahsonkhan deleted the AddPinMethod branch March 28, 2018 00:05
@BruceForstall
Copy link

@ahsonkhan
Copy link
Author

It appears this change has caused 3 regressions in Windows ARM

Are you sure this is the cause? This PR only added an API, which isn't called by anything in coreclr. Why would that cause a regression?

@BruceForstall
Copy link

Ah, looks like it was probably #17161. The ARM builds share x86 tests builds, and both used this PR.

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.

6 participants