File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
exercises/practice/reverse-string/.approaches/span Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -56,6 +56,16 @@ So what is the limit for the amount of memory we can allocate?
56
56
Well, this depends on how memory has already been allocated on the stack.
57
57
That said, a small test program successfully stack-allocated memory for ` 750_000 ` characters, so you might be fine.
58
58
59
+ ## Alternative
60
+
61
+ It is possible to use an alternative span-based implementation that is more readable, but has the downside of being about twice as slow:
62
+
63
+ ``` csharp
64
+ Span < char > chars = stackalloc char [input .Length ];
65
+ input .AsSpan ().CopyTo (chars );
66
+ chars .Reverse ();
67
+ ```
68
+
59
69
## Performance
60
70
61
71
If you're interested in how this approach's performance compares to other approaches, check the [ performance approach] [ approach-performance ] .
You can’t perform that action at this time.
0 commit comments