dotnet / dotnet-api-docs

.NET API reference documentation (.NET 5+, .NET Core, .NET Framework)
https://docs.microsoft.com/dotnet/api/
Other
718 stars 1.56k forks source link

Span<T>(Void*, Int32) points to original unmanaged block or copies it? #1873

Open chrisgull opened 5 years ago

chrisgull commented 5 years ago

Doc is unclear - does Span<T>(Void*, Int32) refer to the original unmanaged memory block, or copy the unmanaged data into a T[] managed object, that is then pinned when a pinnable ref is requested? The former would certainly be desired, at least in some instances, but from tests it seems impossible to get the address of the original unmanaged object when requesting a pinnable ref. Doc needs to be clear here.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

mikedn commented 5 years ago

Spans never copy anything by themselves. That would defeat their purpose, to be able to access portions of an array or arbitrary memory in an uniform manner and without significant overhead.

chrisgull commented 5 years ago

Right - issue here is unclear documentation.