File tree Expand file tree Collapse file tree 2 files changed +47
-4
lines changed
src/Tests/MemoryModelTest Expand file tree Collapse file tree 2 files changed +47
-4
lines changed Original file line number Diff line number Diff line change 1+ using System ;
2+ using System . Runtime . InteropServices ;
3+
4+ namespace MemoryModelTest ;
5+
6+ public static class MemoryMarshalTest
7+ {
8+
9+ #region Constants & Statics
10+
11+ public static unsafe void GetReferenceNull_WithEmptySpanTest ( )
12+ {
13+ #pragma warning disable CA1825
14+ var array = new byte [ 0 ] ;
15+ #pragma warning restore CA1825
16+ var a = new Span < byte > ( array ) ;
17+
18+ ref var r = ref MemoryMarshal . GetReference ( a ) ;
19+ //r is 0
20+
21+ fixed ( byte * pbData = & MemoryMarshal . GetReference ( a ) )
22+ {
23+ //pbData is not null, 0x000002191c40ee30
24+ }
25+ }
26+
27+ public static unsafe void GetReferenceNullTest ( )
28+ {
29+ var a = new Span < byte > ( null ) ;
30+
31+ ref var r = ref MemoryMarshal . GetReference ( a ) ;
32+ //'r' threw an exception of type 'System.NullReferenceException'
33+
34+ fixed ( byte * pbData = & MemoryMarshal . GetReference ( a ) )
35+ {
36+ //pbData is 0x0000000000000000, is null
37+ }
38+ }
39+
40+ #endregion
41+
42+ }
Original file line number Diff line number Diff line change 1- using System . Threading . Tasks ;
2-
31namespace MemoryModelTest ;
42
53internal static class Program
64{
75
86 #region Constants & Statics
97
10- public static async Task Main ( string [ ] args )
8+ public static void Main ( string [ ] args )
119 {
1210 //VolatileTest.Worker_Test();
1311 //Console.WriteLine();
@@ -40,7 +38,10 @@ public static async Task Main(string[] args)
4038 //MemoryOwnerTest.SliceTest();
4139 //await MemoryOwnerTest.AllocateLengthTestAsync();
4240
43- await SpanOwnerTest . Test ( ) ;
41+ //await SpanOwnerTest.Test();
42+
43+ MemoryMarshalTest . GetReferenceNullTest ( ) ;
44+ MemoryMarshalTest . GetReferenceNull_WithEmptySpanTest ( ) ;
4445 }
4546
4647 #endregion
You can’t perform that action at this time.
0 commit comments