Skip to content

Commit

Permalink
[IO] replaced Marshal.SizeOf with Unsafe.SizeOf
Browse files Browse the repository at this point in the history
  • Loading branch information
luithefirst committed May 13, 2024
1 parent d11a624 commit 4c2f1a1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/Aardvark.Base.IO/StreamCodeReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public long ReadArray<T>(T[] array, long index, long count)
#else
unsafe
{
var sizeOfT = Marshal.SizeOf(typeof(T));
var sizeOfT = Unsafe.SizeOf<T>();
var hack = new ByteArrayUnion();
hack.structs = array;

Expand Down Expand Up @@ -181,7 +181,7 @@ public long ReadArray<T>(T[,] array, long count)
if (count < 1) return 0;

#if NET6_0_OR_GREATER
var sizeOfT = Marshal.SizeOf(typeof(T));
var sizeOfT = Unsafe.SizeOf<T>();
var span = MemoryMarshal.CreateSpan(ref MemoryMarshal.GetArrayDataReference(array), (int)count * sizeOfT);

var bytesToRead = span.Length;
Expand All @@ -200,7 +200,7 @@ public long ReadArray<T>(T[,] array, long count)
#else
unsafe
{
var sizeOfT = Marshal.SizeOf(typeof(T));
var sizeOfT = Unsafe.SizeOf<T>();
var hack = new ByteArrayUnion();
hack.structs = array;

Expand Down Expand Up @@ -238,7 +238,7 @@ public long ReadArray<T>(T[, ,] array, long count)
{
if (count < 1) return 0;
#if NET6_0_OR_GREATER
var sizeOfT = Marshal.SizeOf(typeof(T));
var sizeOfT = Unsafe.SizeOf<T>();
var span = MemoryMarshal.CreateSpan(ref MemoryMarshal.GetArrayDataReference(array), (int)count * sizeOfT);

var bytesToRead = span.Length;
Expand All @@ -257,7 +257,7 @@ public long ReadArray<T>(T[, ,] array, long count)
#else
unsafe
{
var sizeOfT = Marshal.SizeOf(typeof(T));
var sizeOfT = Unsafe.SizeOf<T>();
var hack = new ByteArrayUnion();
hack.structs = array;

Expand Down
10 changes: 5 additions & 5 deletions src/Aardvark.Base.IO/StreamCodeWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public void WriteArray<T>(T[] array, long index, long count)
#else
unsafe
{
var sizeOfT = Marshal.SizeOf(typeof(T));
var sizeOfT = Unsafe.SizeOf<T>();

var hack = new ByteArrayUnion();
hack.structs = array;
Expand Down Expand Up @@ -167,13 +167,13 @@ public void WriteArray<T>(T[,] array, long count)
{
if (count < 1) return;
#if NET6_0_OR_GREATER
var sizeOfT = Marshal.SizeOf(typeof(T));
var sizeOfT = Unsafe.SizeOf<T>();
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<T>();

var hack = new ByteArrayUnion();
hack.structs = array;
Expand Down Expand Up @@ -208,13 +208,13 @@ public void WriteArray<T>(T[, ,] array, long count)
{
if (count < 1) return;
#if NET6_0_OR_GREATER
var sizeOfT = Marshal.SizeOf(typeof(T));
var sizeOfT = Unsafe.SizeOf<T>();
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<T>();

var hack = new ByteArrayUnion();
hack.structs = array;
Expand Down

0 comments on commit 4c2f1a1

Please sign in to comment.