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

Add MarshalString.FromAbiUnsafe API #1400

Merged
merged 3 commits into from
Nov 30, 2023

Conversation

Sergio0694
Copy link
Member

Extracted from #1399

Description

This PR adds a new MarshalString API:

public static ReadOnlySpan<char> FromAbiUnsafe(IntPtr value);

This allows marshalling an HSTRING to a ReadOnlySpan<char> value, without allocating a temporary string. The "Unsafe" suffix matches the naming convention in the BCL for methods that are not safe when misused. In this case, callers have to make sure not to escape the returned ReadOnlySpan<char> value outside of the scope where the HSTRING is valid.

Developers can use this where appropriate, and we can also use this in eg. marshalling stubs in the future. Once we update the projections to require C# 11, we can also restore #1399 and leverage this API there as well.

@Sergio0694 Sergio0694 added enhancement New feature or request performance Related to performance work gc Related to garbage collection labels Nov 30, 2023
@Sergio0694 Sergio0694 force-pushed the user/sergiopedri/from-abi-unsafe branch from c4b170d to c6b0708 Compare November 30, 2023 11:26
@Sergio0694 Sergio0694 force-pushed the user/sergiopedri/from-abi-unsafe branch from c6b0708 to 1818410 Compare November 30, 2023 15:02
@Sergio0694
Copy link
Member Author

@manodasanW the test failure in Debug x64 seems unrelated, maybe transient? Could you re-trigger that CI job? 🙂

@Sergio0694 Sergio0694 merged commit c68a482 into staging/AOT Nov 30, 2023
9 checks passed
@Sergio0694 Sergio0694 deleted the user/sergiopedri/from-abi-unsafe branch November 30, 2023 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request gc Related to garbage collection performance Related to performance work
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants