Skip to content

Commit 3626ff7

Browse files
committed
Add MemoryTest
1 parent 76f8c9e commit 3626ff7

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
4+
namespace MemoryModelTest;
5+
6+
public static class MemoryTest
7+
{
8+
9+
#region Constants & Statics
10+
11+
public static async Task MemoryToSpanTestAsync()
12+
{
13+
await Task.Yield();
14+
15+
Memory<int> memory = new int[5];
16+
var span = memory.Span; // 高性能访问
17+
span[0] = 42;
18+
19+
Console.WriteLine(span[0]);
20+
}
21+
22+
#endregion
23+
24+
}

src/Tests/MemoryModelTest/Program.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
using System.Threading.Tasks;
2+
13
namespace MemoryModelTest;
24

35
internal static class Program
46
{
57

68
#region Constants & Statics
79

8-
public static void Main(string[] args)
10+
public static async Task Main(string[] args)
911
{
1012
//VolatileTest.Worker_Test();
1113
//Console.WriteLine();
@@ -34,7 +36,9 @@ public static void Main(string[] args)
3436

3537
//MemoryOwnerTest.SliceTest();
3638

37-
SpanOwnerTest.Test();
39+
//SpanOwnerTest.Test();
40+
41+
await MemoryTest.MemoryToSpanTestAsync();
3842
}
3943

4044
#endregion

0 commit comments

Comments
 (0)