Skip to content

Commit fe16905

Browse files
committed
Changed from Unsafe.CopyBlock to Unsafe.CopyBlockUnaligned
1 parent 5278550 commit fe16905

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# UnmanagedMemoryUtils
2+
Hosted on github: https://github.com/Azengar/UnmanagedMemoryUtils.
3+
24
A .NET collection of utilities for working with unmanaged memory.
35

46
Provides faster alternatives to `Memory<T>` and `ReadOnlyMemory<T>` in addition to accessing unmanaged string from managed code.

UnmanagedMemoryUtils/UnmanagedMemoryUtils/ReadOnlyUnmanagedMemory.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public readonly ReadOnlyUnmanagedMemory Slice(int start, int length)
185185
public readonly void CopyTo(UnmanagedMemory destination)
186186
{
187187
Debug.Assert(destination.Length >= m_Length);
188-
Unsafe.CopyBlock(destination.VoidPointer, VoidPointer, (uint)Length);
188+
Unsafe.CopyBlockUnaligned(destination.VoidPointer, VoidPointer, (uint)Length);
189189
}
190190

191191
/// <summary>
@@ -199,7 +199,7 @@ public readonly void CopyTo(UnmanagedMemory destination)
199199
public readonly void CopyTo(Memory<byte> destination)
200200
{
201201
Debug.Assert(destination.Length >= m_Length);
202-
Unsafe.CopyBlock(ref destination.Span[0], ref ((byte*)Pointer)[0], (uint)Length);
202+
Unsafe.CopyBlockUnaligned(ref destination.Span[0], ref ((byte*)Pointer)[0], (uint)Length);
203203
}
204204

205205
/// <summary>
@@ -213,7 +213,7 @@ public readonly void CopyTo(Memory<byte> destination)
213213
public readonly void CopyTo(byte[] destination)
214214
{
215215
Debug.Assert(destination.Length >= m_Length);
216-
Unsafe.CopyBlock(ref destination[0], ref ((byte*)Pointer)[0], (uint)Length);
216+
Unsafe.CopyBlockUnaligned(ref destination[0], ref ((byte*)Pointer)[0], (uint)Length);
217217
}
218218

219219
/// <summary>
@@ -492,7 +492,7 @@ public readonly ReadOnlyUnmanagedMemory<T> Slice(int start, int length)
492492
public readonly void CopyTo(UnmanagedMemory<T> destination)
493493
{
494494
Debug.Assert(destination.Length >= m_Length);
495-
Unsafe.CopyBlock(TypedPointer, destination.TypedPointer, (uint)ByteLength);
495+
Unsafe.CopyBlockUnaligned(TypedPointer, destination.TypedPointer, (uint)ByteLength);
496496
}
497497

498498
/// <summary>
@@ -507,7 +507,7 @@ public readonly void CopyTo(Memory<T> destination)
507507
{
508508
Debug.Assert(destination.Length >= m_Length);
509509
Memory<byte> buffer = Unsafe.As<Memory<T>, Memory<byte>>(ref destination);
510-
Unsafe.CopyBlock(ref buffer.Span[0], ref ((byte*)Pointer)[0], (uint)ByteLength);
510+
Unsafe.CopyBlockUnaligned(ref buffer.Span[0], ref ((byte*)Pointer)[0], (uint)ByteLength);
511511
}
512512

513513
/// <summary>
@@ -522,7 +522,7 @@ public readonly void CopyTo(T[] destination)
522522
{
523523
Debug.Assert(destination.Length >= m_Length);
524524
Span<byte> buffer = MemoryMarshal.AsBytes(destination.AsSpan());
525-
Unsafe.CopyBlock(ref buffer[0], ref ((byte*)Pointer)[0], (uint)ByteLength);
525+
Unsafe.CopyBlockUnaligned(ref buffer[0], ref ((byte*)Pointer)[0], (uint)ByteLength);
526526
}
527527

528528
/// <summary>

UnmanagedMemoryUtils/UnmanagedMemoryUtils/UnmanagedMemory.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public readonly UnmanagedMemory Slice(int start, int length)
185185
public readonly void CopyTo(UnmanagedMemory destination)
186186
{
187187
Debug.Assert(destination.Length >= m_Length);
188-
Unsafe.CopyBlock(destination.VoidPointer, VoidPointer, (uint)Length);
188+
Unsafe.CopyBlockUnaligned(destination.VoidPointer, VoidPointer, (uint)Length);
189189
}
190190

191191
/// <summary>
@@ -199,7 +199,7 @@ public readonly void CopyTo(UnmanagedMemory destination)
199199
public readonly void CopyTo(Memory<byte> destination)
200200
{
201201
Debug.Assert(destination.Length >= m_Length);
202-
Unsafe.CopyBlock(ref destination.Span[0], ref Span[0], (uint)Length);
202+
Unsafe.CopyBlockUnaligned(ref destination.Span[0], ref Span[0], (uint)Length);
203203
}
204204

205205
/// <summary>
@@ -213,7 +213,7 @@ public readonly void CopyTo(Memory<byte> destination)
213213
public readonly void CopyTo(byte[] destination)
214214
{
215215
Debug.Assert(destination.Length >= m_Length);
216-
Unsafe.CopyBlock(ref destination[0], ref Span[0], (uint)Length);
216+
Unsafe.CopyBlockUnaligned(ref destination[0], ref Span[0], (uint)Length);
217217
}
218218

219219
/// <summary>
@@ -494,7 +494,7 @@ public readonly UnmanagedMemory<T> Slice(int start, int length)
494494
public readonly void CopyTo(UnmanagedMemory<T> destination)
495495
{
496496
Debug.Assert(destination.Length >= m_Length);
497-
Unsafe.CopyBlock(TypedPointer, destination.TypedPointer, (uint)ByteLength);
497+
Unsafe.CopyBlockUnaligned(TypedPointer, destination.TypedPointer, (uint)ByteLength);
498498
}
499499

500500
/// <summary>
@@ -509,7 +509,7 @@ public readonly void CopyTo(Memory<T> destination)
509509
{
510510
Debug.Assert(destination.Length >= m_Length);
511511
Memory<byte> buffer = Unsafe.As<Memory<T>, Memory<byte>>(ref destination);
512-
Unsafe.CopyBlock(ref buffer.Span[0], ref ((byte*)Pointer)[0], (uint)ByteLength);
512+
Unsafe.CopyBlockUnaligned(ref buffer.Span[0], ref ((byte*)Pointer)[0], (uint)ByteLength);
513513
}
514514

515515
/// <summary>
@@ -524,7 +524,7 @@ public readonly void CopyTo(T[] destination)
524524
{
525525
Debug.Assert(destination.Length >= m_Length);
526526
Span<byte> buffer = MemoryMarshal.AsBytes(destination.AsSpan());
527-
Unsafe.CopyBlock(ref buffer[0], ref ((byte*)Pointer)[0], (uint)ByteLength);
527+
Unsafe.CopyBlockUnaligned(ref buffer[0], ref ((byte*)Pointer)[0], (uint)ByteLength);
528528
}
529529

530530
/// <summary>

UnmanagedMemoryUtils/UnmanagedMemoryUtils/UnmanagedMemoryUtils.csproj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
88
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
99
<Title>UnmanagedMemoryUtils</Title>
10-
<VersionPrefix>1.0.1</VersionPrefix>
10+
<VersionPrefix>1.0.2</VersionPrefix>
1111
<PackageReadmeFile>README.md</PackageReadmeFile>
1212
<Description>A .NET collection of utilities for working with unmanaged memory.
1313
Provides faster alternatives to Memory&lt;T&gt; and ReadOnlyMemory&lt;T&gt; in addition to accessing unmanaged string from managed code.</Description>
14+
<Authors>Azengar</Authors>
15+
<RepositoryUrl>https://github.com/Azengar/UnmanagedMemoryUtils</RepositoryUrl>
16+
<RepositoryType>git</RepositoryType>
17+
<PackageTags>.NET;C#</PackageTags>
18+
<Copyright>BSD-3-Clause license</Copyright>
19+
<PackageProjectUrl>https://github.com/Azengar/UnmanagedMemoryUtils</PackageProjectUrl>
20+
<PackageReleaseNotes>* Changed from `Unsafe.CopyBlock` to `Unsafe.CopyBlockUnaligned`</PackageReleaseNotes>
1421
</PropertyGroup>
1522
<ItemGroup>
1623
<None Include="..\..\README.md" Pack="true" PackagePath="\" />

0 commit comments

Comments
 (0)