Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update NonBlittable.cs
  • Loading branch information
AaronRobinsonMSFT authored and github-actions committed Oct 5, 2022
commit eea4dd3d4ebc7cd8bd1eb9ca5cc1afaa4992b0cc
Original file line number Diff line number Diff line change
Expand Up @@ -502,14 +502,14 @@ public void FromManaged(List<T> managed, Span<TUnmanagedElement> buffer)

_list = managed;
// Always allocate at least one byte when the list is zero-length.
int spaceToAllocate = Math.Max(managed.Count, 1);
if (spaceToAllocate <= buffer.Length)
int countToAllocate = Math.Max(managed.Count, 1);
if (countToAllocate <= buffer.Length)
{
_span = buffer[0..spaceToAllocate];
_span = buffer[0..countToAllocate];
}
else
{
_allocatedMemory = Marshal.AllocCoTaskMem(spaceToAllocate);
_allocatedMemory = Marshal.AllocCoTaskMem(countToAllocate * sizeof(TUnmanagedElement));
_span = new Span<TUnmanagedElement>((void*)_allocatedMemory, managed.Count);
}
}
Expand Down