Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Pin()

unsafe MemoryHandle System.ReadOnlyMemory< T >.Pin ( )
inline

Definition at line 163 of file ReadOnlyMemory.cs.

164 {
165 object @object = _object;
166 if (@object != null)
167 {
168 if (typeof(T) == typeof(char) && @object is string text)
169 {
170 GCHandle handle = GCHandle.Alloc(@object, GCHandleType.Pinned);
171 return new MemoryHandle(Unsafe.AsPointer(ref Unsafe.Add(ref text.GetRawStringData(), _index)), handle);
172 }
174 {
175 if (_index < 0)
176 {
177 void* pointer = Unsafe.Add<T>(Unsafe.AsPointer(ref MemoryMarshal.GetArrayDataReference(Unsafe.As<T[]>(@object))), _index & 0x7FFFFFFF);
178 return new MemoryHandle(pointer);
179 }
180 GCHandle handle2 = GCHandle.Alloc(@object, GCHandleType.Pinned);
181 void* pointer2 = Unsafe.Add<T>(Unsafe.AsPointer(ref MemoryMarshal.GetArrayDataReference(Unsafe.As<T[]>(@object))), _index);
182 return new MemoryHandle(pointer2, handle2);
183 }
184 return Unsafe.As<MemoryManager<T>>(@object).Pin(_index);
185 }
186 return default(MemoryHandle);
187 }
static unsafe bool ObjectHasComponentSize(object obj)
static unsafe ref byte GetArrayDataReference(Array array)
readonly object _object
unsafe MemoryHandle Pin()
static GCHandle Alloc(object? value)
Definition GCHandle.cs:81

References System.ReadOnlyMemory< T >._index, System.ReadOnlyMemory< T >._object, System.Runtime.InteropServices.GCHandle.Alloc(), System.Runtime.InteropServices.MemoryMarshal.GetArrayDataReference(), System.handle, System.Runtime.CompilerServices.RuntimeHelpers.ObjectHasComponentSize(), System.ReadOnlyMemory< T >.Pin(), System.pointer, and System.text.

Referenced by System.IO.Strategies.Net5CompatFileStreamStrategy.MemoryFileStreamCompletionSource.MemoryFileStreamCompletionSource(), System.ReadOnlyMemory< T >.Pin(), System.Net.Quic.Implementations.MsQuic.MsQuicStream.SendReadOnlyMemoryListAsync(), System.Net.Quic.Implementations.MsQuic.MsQuicStream.SendReadOnlySequenceAsync(), System.IO.Compression.Deflater.SetInput(), and System.IO.Compression.Inflater.SetInput().