Skip to content

Commit

Permalink
Update xml comment for {ReadOnly}Memory.Pin method (dotnet/corefxdotn…
Browse files Browse the repository at this point in the history
…et/coreclr#29137) (dotnet/coreclr#17709)

Signed-off-by: dotnet-bot-corefx-mirror <[email protected]>

Commit migrated from dotnet/coreclr@2ac1fa8
  • Loading branch information
dotnet-bot authored and ahsonkhan committed Apr 20, 2018
1 parent 8619ba0 commit eb0a997
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
21 changes: 17 additions & 4 deletions src/coreclr/src/mscorlib/shared/System/Memory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,26 @@ public unsafe MemoryHandle Pin()
}
else if (_object is T[] array)
{
GCHandle handle = _length < 0 ? default : GCHandle.Alloc(array, GCHandleType.Pinned);
// Array is already pre-pinned
if (_length < 0)
{
#if FEATURE_PORTABLE_SPAN
void* pointer = Unsafe.Add<T>((void*)handle.AddrOfPinnedObject(), _index);
void* pointer = Unsafe.Add<T>(Unsafe.AsPointer(ref MemoryMarshal.GetReference<T>(array)), _index);
#else
void* pointer = Unsafe.Add<T>(Unsafe.AsPointer(ref array.GetRawSzArrayData()), _index);
void* pointer = Unsafe.Add<T>(Unsafe.AsPointer(ref array.GetRawSzArrayData()), _index);
#endif // FEATURE_PORTABLE_SPAN
return new MemoryHandle(pointer, handle);
return new MemoryHandle(pointer);
}
else
{
GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned);
#if FEATURE_PORTABLE_SPAN
void* pointer = Unsafe.Add<T>((void*)handle.AddrOfPinnedObject(), _index);
#else
void* pointer = Unsafe.Add<T>(Unsafe.AsPointer(ref array.GetRawSzArrayData()), _index);
#endif // FEATURE_PORTABLE_SPAN
return new MemoryHandle(pointer, handle);
}
}
return default;
}
Expand Down
21 changes: 17 additions & 4 deletions src/coreclr/src/mscorlib/shared/System/ReadOnlyMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,26 @@ public unsafe MemoryHandle Pin()
}
else if (_object is T[] array)
{
GCHandle handle = _length < 0 ? default : GCHandle.Alloc(array, GCHandleType.Pinned);
// Array is already pre-pinned
if (_length < 0)
{
#if FEATURE_PORTABLE_SPAN
void* pointer = Unsafe.Add<T>((void*)handle.AddrOfPinnedObject(), _index);
void* pointer = Unsafe.Add<T>(Unsafe.AsPointer(ref MemoryMarshal.GetReference<T>(array)), _index);
#else
void* pointer = Unsafe.Add<T>(Unsafe.AsPointer(ref array.GetRawSzArrayData()), _index);
void* pointer = Unsafe.Add<T>(Unsafe.AsPointer(ref array.GetRawSzArrayData()), _index);
#endif // FEATURE_PORTABLE_SPAN
return new MemoryHandle(pointer, handle);
return new MemoryHandle(pointer);
}
else
{
GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned);
#if FEATURE_PORTABLE_SPAN
void* pointer = Unsafe.Add<T>((void*)handle.AddrOfPinnedObject(), _index);
#else
void* pointer = Unsafe.Add<T>(Unsafe.AsPointer(ref array.GetRawSzArrayData()), _index);
#endif // FEATURE_PORTABLE_SPAN
return new MemoryHandle(pointer, handle);
}
}
return default;
}
Expand Down

0 comments on commit eb0a997

Please sign in to comment.