-
Notifications
You must be signed in to change notification settings - Fork 1k
Porting code to System.Memory
With PR https://github.com/mono/monodevelop/pull/5570, we now have support for using the new Span/Memory APIs.
What does this entail? Lots of performance niceties.
This guide will go through common patterns that can be ported over to the new APIs with a mapping for each method and how it should be ported.
To get a ReadOnlySpan<char> from a string, use AsSpan().
To get a string from a ReadOnlySpan<char>, use ToString().
We currently do not have stackalloc span support until we use C# 7.3, so use "mystring".AsSpan() where you need a local span.
| String API | ReadOnlySpan API |
|---|---|
| == | SequenceEquals |
| Substring | Slice |
| Trim* | Trim* |
| Starts/EndsWith | Starts/EndsWith |
| Equals | Equals |
Note: any StringComparison other than Ordinal/OrdinalIgnoreCase will convert to a string internally, so you won't get any benefit for equality there.
Normally, a string substring then a trim would allocate two strings.
Bulding and Running
Writing Add-ins
MonoDevelop API
MonoDevelop Design and Architecure
- The Project Model
- Error and Exception Handling
- The Command System
- The Service Model
- The Document/View Model
MonoDevelop Coding Guides