From 4c2f1a1a88061889653a3a1dcc45f782a3375cc0 Mon Sep 17 00:00:00 2001 From: Christian Luksch Date: Mon, 13 May 2024 18:20:28 +0200 Subject: [PATCH] [IO] replaced Marshal.SizeOf with Unsafe.SizeOf --- src/Aardvark.Base.IO/StreamCodeReader.cs | 10 +++++----- src/Aardvark.Base.IO/StreamCodeWriter.cs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Aardvark.Base.IO/StreamCodeReader.cs b/src/Aardvark.Base.IO/StreamCodeReader.cs index 79e62821..ce07af4a 100644 --- a/src/Aardvark.Base.IO/StreamCodeReader.cs +++ b/src/Aardvark.Base.IO/StreamCodeReader.cs @@ -145,7 +145,7 @@ public long ReadArray(T[] array, long index, long count) #else unsafe { - var sizeOfT = Marshal.SizeOf(typeof(T)); + var sizeOfT = Unsafe.SizeOf(); var hack = new ByteArrayUnion(); hack.structs = array; @@ -181,7 +181,7 @@ public long ReadArray(T[,] array, long count) if (count < 1) return 0; #if NET6_0_OR_GREATER - var sizeOfT = Marshal.SizeOf(typeof(T)); + var sizeOfT = Unsafe.SizeOf(); var span = MemoryMarshal.CreateSpan(ref MemoryMarshal.GetArrayDataReference(array), (int)count * sizeOfT); var bytesToRead = span.Length; @@ -200,7 +200,7 @@ public long ReadArray(T[,] array, long count) #else unsafe { - var sizeOfT = Marshal.SizeOf(typeof(T)); + var sizeOfT = Unsafe.SizeOf(); var hack = new ByteArrayUnion(); hack.structs = array; @@ -238,7 +238,7 @@ public long ReadArray(T[, ,] array, long count) { if (count < 1) return 0; #if NET6_0_OR_GREATER - var sizeOfT = Marshal.SizeOf(typeof(T)); + var sizeOfT = Unsafe.SizeOf(); var span = MemoryMarshal.CreateSpan(ref MemoryMarshal.GetArrayDataReference(array), (int)count * sizeOfT); var bytesToRead = span.Length; @@ -257,7 +257,7 @@ public long ReadArray(T[, ,] array, long count) #else unsafe { - var sizeOfT = Marshal.SizeOf(typeof(T)); + var sizeOfT = Unsafe.SizeOf(); var hack = new ByteArrayUnion(); hack.structs = array; diff --git a/src/Aardvark.Base.IO/StreamCodeWriter.cs b/src/Aardvark.Base.IO/StreamCodeWriter.cs index f4d07215..6a765d9a 100644 --- a/src/Aardvark.Base.IO/StreamCodeWriter.cs +++ b/src/Aardvark.Base.IO/StreamCodeWriter.cs @@ -132,7 +132,7 @@ public void WriteArray(T[] array, long index, long count) #else unsafe { - var sizeOfT = Marshal.SizeOf(typeof(T)); + var sizeOfT = Unsafe.SizeOf(); var hack = new ByteArrayUnion(); hack.structs = array; @@ -167,13 +167,13 @@ public void WriteArray(T[,] array, long count) { if (count < 1) return; #if NET6_0_OR_GREATER - var sizeOfT = Marshal.SizeOf(typeof(T)); + var sizeOfT = Unsafe.SizeOf(); var byteSpan = MemoryMarshal.CreateSpan(ref MemoryMarshal.GetArrayDataReference(array), (int)count * sizeOfT); base.Write(byteSpan); #else unsafe { - var sizeOfT = Marshal.SizeOf(typeof(T)); + var sizeOfT = Unsafe.SizeOf(); var hack = new ByteArrayUnion(); hack.structs = array; @@ -208,13 +208,13 @@ public void WriteArray(T[, ,] array, long count) { if (count < 1) return; #if NET6_0_OR_GREATER - var sizeOfT = Marshal.SizeOf(typeof(T)); + var sizeOfT = Unsafe.SizeOf(); var byteSpan = MemoryMarshal.CreateSpan(ref MemoryMarshal.GetArrayDataReference(array), (int)count * sizeOfT); base.Write(byteSpan); #else unsafe { - var sizeOfT = Marshal.SizeOf(typeof(T)); + var sizeOfT = Unsafe.SizeOf(); var hack = new ByteArrayUnion(); hack.structs = array;