File tree Expand file tree Collapse file tree 4 files changed +46
-5
lines changed
src/Tests/MemoryModelTest Expand file tree Collapse file tree 4 files changed +46
-5
lines changed Original file line number Diff line number Diff line change 11using CommunityToolkit . HighPerformance . Buffers ;
2+ using System ;
3+ using System . Threading . Tasks ;
24
35namespace MemoryModelTest ;
46
@@ -7,6 +9,19 @@ public static class MemoryOwnerTest
79
810 #region Constants & Statics
911
12+ public static async Task AllocateLengthTestAsync ( )
13+ {
14+ await Task . Yield ( ) ;
15+
16+ using var buffer = MemoryOwner < int > . Allocate ( 1 ) ;
17+
18+ var memory = buffer . Memory ;
19+ memory . Span [ 0 ] = 84 ;
20+
21+ Console . WriteLine ( string . Join ( ' ' , memory . ToArray ( ) ) ) ;
22+ //output: 84
23+ }
24+
1025 public static void SliceTest ( )
1126 {
1227 using var buffer = MemoryOwner < int > . Allocate ( 42 ) ;
Original file line number Diff line number Diff line change 11using System ;
2+ using System . Buffers ;
23using System . Threading . Tasks ;
34
45namespace MemoryModelTest ;
@@ -8,6 +9,21 @@ public static class MemoryTest
89
910 #region Constants & Statics
1011
12+ public static async Task MemoryPoolTestAsync ( )
13+ {
14+ await Task . Yield ( ) ;
15+
16+ var owner = MemoryPool < byte > . Shared . Rent ( 1 ) ;
17+
18+ var memory = owner . Memory ;
19+ memory . Span [ 0 ] = 84 ;
20+
21+ Console . WriteLine ( string . Join ( ' ' , memory . ToArray ( ) ) ) ;
22+ //output:84 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
23+
24+ owner . Dispose ( ) ;
25+ }
26+
1127 public static async Task MemoryToSpanTestAsync ( )
1228 {
1329 await Task . Yield ( ) ;
Original file line number Diff line number Diff line change @@ -34,11 +34,13 @@ public static async Task Main(string[] args)
3434
3535 //ArrayPoolBufferWriterTest.Test();
3636
37- //MemoryOwnerTest.SliceTest();
37+ //await MemoryTest.MemoryToSpanTestAsync();
38+ //await MemoryTest.MemoryPoolTestAsync();
3839
39- //SpanOwnerTest.Test();
40+ //MemoryOwnerTest.SliceTest();
41+ //await MemoryOwnerTest.AllocateLengthTestAsync();
4042
41- await MemoryTest . MemoryToSpanTestAsync ( ) ;
43+ await SpanOwnerTest . Test ( ) ;
4244 }
4345
4446 #endregion
Original file line number Diff line number Diff line change 11using CommunityToolkit . HighPerformance . Buffers ;
2+ using System ;
3+ using System . Threading . Tasks ;
24
35namespace MemoryModelTest ;
46
@@ -7,11 +9,17 @@ public static class SpanOwnerTest
79
810 #region Constants & Statics
911
10- public static void Test ( )
12+ public static async Task Test ( )
1113 {
12- using var buffer = SpanOwner < int > . Allocate ( 100 ) ;
14+ await Task . Yield ( ) ;
15+
16+ using var buffer = SpanOwner < int > . Allocate ( 1 ) ;
1317
1418 var span = buffer . Span ;
19+ span [ 0 ] = 84 ;
20+
21+ Console . WriteLine ( string . Join ( ' ' , span . ToArray ( ) ) ) ;
22+ //output: 84
1523 }
1624
1725 #endregion
You can’t perform that action at this time.
0 commit comments