-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Change OwnedMemory Pin to take an optional integer offset #24126
Comments
|
How would that work? Wouldn't we need to add getters to the private fields of MemoryHandle (for example, for memoryHandle = ((OwnedMemory<T>)_arrayOrOwnedMemory).Pin();
void* pointer = (void*)((byte*)memoryHandle.Pointer + ((_index & RemoveOwnedFlagBitMask) * Unsafe.SizeOf<T>()));
memoryHandle = new MemoryHandle((OwnedMemory<T>)_arrayOrOwnedMemory, pointer); // what about GCHandle? |
Is that the only benefit?
Your example is in the same assembly. We could add internal getters, we could make the fields internal, etc., or simply keep the internal AddOffset we have today. What's the key scenario for exposing this functionality? |
The key scenario is using OwnedMemory directly without using Memory/RreadOnlyMemory. Memory and friends are factories of spans. They are very general purpose, e.g. they handle arrays, native pointers, and now strings. Quite often (when using OwnedMemory internally), it's more efficient to create a custom span factory to avoid the overhead associated with the general purpose Memory. But without the Pin(int) APIs, it's not possible for the factory to be slicable (as explained in @ahsonkhan's comment). |
FYI: The API review discussion was recorded - see https://youtu.be/BI3iXFT8H7E?t=3747 (2 min duration) |
Reverted here - dotnet/coreclr#15516 Re-opening. |
The change from the previous PR (dotnet/coreclr#15410) was reverted here (dotnet/coreclr#15516) to unblock CoreCLR ingestion into CoreFX - this change was causing CoreFX socket tests to fail. See trail of build update failures: It requires further investigation to why that is happening to resolve it. TBD Related to dotnet/corefx#25770 FYI @KrzysztofCwalina, @jkotas, @stephentoub, @davidfowl, @pakrym |
Since this appears to a byte offset, despite OwnedMemory<> having a type parameter for the element, shouldn't the argument be named "byteOffset"? Right now, I have to play a guessing game to figure out what's intended... |
I am fine with this change. |
Related to https://github.com/dotnet/corefx/issues/24317 and dotnet/corefx#24323 (comment)
API Proposal
Change:
To:
Usage
Example from NativeOwnedMemory:
Would become:
The following can then be re-written from Memory.Retain:
To:
We can then remove the internal AddOffset method here which was added in dotnet/corefx#24323.
cc @KrzysztofCwalina, @stephentoub, @karelz, @terrajobst, @pakrym
The text was updated successfully, but these errors were encountered: