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

◆ Pin()

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

Definition at line 223 of file Memory.cs.

224 {
225 object @object = _object;
226 if (@object != null)
227 {
228 if (typeof(T) == typeof(char) && @object is string text)
229 {
230 GCHandle handle = GCHandle.Alloc(@object, GCHandleType.Pinned);
231 return new MemoryHandle(Unsafe.AsPointer(ref Unsafe.Add(ref text.GetRawStringData(), _index)), handle);
232 }
234 {
235 if (_index < 0)
236 {
237 void* pointer = Unsafe.Add<T>(Unsafe.AsPointer(ref MemoryMarshal.GetArrayDataReference(Unsafe.As<T[]>(@object))), _index & 0x7FFFFFFF);
238 return new MemoryHandle(pointer);
239 }
240 GCHandle handle2 = GCHandle.Alloc(@object, GCHandleType.Pinned);
241 void* pointer2 = Unsafe.Add<T>(Unsafe.AsPointer(ref MemoryMarshal.GetArrayDataReference(Unsafe.As<T[]>(@object))), _index);
242 return new MemoryHandle(pointer2, handle2);
243 }
244 return Unsafe.As<MemoryManager<T>>(@object).Pin(_index);
245 }
246 return default(MemoryHandle);
247 }
static unsafe bool ObjectHasComponentSize(object obj)
static unsafe ref byte GetArrayDataReference(Array array)
unsafe MemoryHandle Pin()
Definition Memory.cs:223
readonly object _object
Definition Memory.cs:15
readonly int _index
Definition Memory.cs:17
static GCHandle Alloc(object? value)
Definition GCHandle.cs:81

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

Referenced by System.Net.Sockets.SocketAsyncEventArgs.DoOperationConnectEx(), and System.Memory< T >.Pin().