dangerous release (possibly memory leak and deadlock)
This commit is contained in:
parent
a1cb6592eb
commit
741d34a5e0
10 changed files with 164 additions and 115 deletions
|
|
@ -1,16 +1,13 @@
|
|||
using System.IO.MemoryMappedFiles;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using StitchATon2.Infra.Buffers;
|
||||
|
||||
namespace StitchATon2.Infra;
|
||||
|
||||
public static class Utils
|
||||
internal static class Utils
|
||||
{
|
||||
private static unsafe uint AlignedSizeOf<T>() where T : unmanaged
|
||||
{
|
||||
uint size = (uint)sizeof(T);
|
||||
return size is 1 or 2 ? size : (uint)((size + 3) & (~3));
|
||||
return size is 1 or 2 ? size : (uint)((size + 3) & ~3);
|
||||
}
|
||||
|
||||
internal static void DangerousReadSpan<T>(this MemoryMappedViewAccessor view, long position, Span<T> span, int offset, int count)
|
||||
|
|
@ -36,10 +33,10 @@ public static class Utils
|
|||
view.SafeMemoryMappedViewHandle.ReadSpan(byteOffset, span.Slice(offset, n));
|
||||
}
|
||||
|
||||
public static ArrayOwner<T> Clone<T>(this ArrayOwner<T> arrayOwner, int length) where T : unmanaged
|
||||
internal static void DangerousWriteSpan<T>(this MemoryMappedViewAccessor view, long position, Span<T> span, int offset, int count)
|
||||
where T : unmanaged
|
||||
{
|
||||
var newArrayOwner = MemoryAllocator.AllocateArray<T>(length);
|
||||
Array.Copy(arrayOwner.Array, 0, newArrayOwner.Array, 0, length);
|
||||
return newArrayOwner;
|
||||
var byteOffset = (ulong)(view.PointerOffset + position);
|
||||
view.SafeMemoryMappedViewHandle.WriteSpan<T>(byteOffset, span.Slice(offset, count));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue