Can Memory<T> be created from a pointer?
Can Memory<T> be created with a pointer and a length? If not, how come?
9 Replies
you would need to use https://github.com/dotnet/runtime/blob/main/src/libraries/Common/src/System/Memory/PointerMemoryManager.cs (or something that does the same thing)
just copy it into your project, and use
myMemoryManager.Memory
Ty this will work! I was going crazy looking for a something in the BCL that does this.
AI Answer:
CreateFromPinnedArray takes an array, not a span, so that does not work
but, there was an attempt
GPT-4:
Still same issue i think
damn
Yeah I tried asking copilot earlier and got a lot of stuff that was incorrect
My last attempt:
Looks like you could use something like this. I didn't test it tho.
then this should work according to ai
This allocates a managed array and has to perform a copy. The
MemoryManager<T>
is the better solutionPlease don't post AI answers, especially because they are often wrong like is the case here