Skip to content

Commit

Permalink
Upgrade to non-prerelease System.Memory and C# 7.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoritzinsky committed Jun 26, 2018
1 parent 23a17e7 commit 9d6092f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Directory.build.props
Expand Up @@ -10,6 +10,6 @@
<PackageProjectUrl>https://github.com/jkoritzinsky/SharpGenTools</PackageProjectUrl>
<Tags>SharpGen;CodeGen;CPlusPlus;COM</Tags>
<RepositoryUrl>https://github.com/jkoritzinsky/SharpGenTools</RepositoryUrl>
<LangVersion>7.2</LangVersion>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
</Project>
4 changes: 2 additions & 2 deletions SharpGen.Runtime/BooleanHelpers.cs
Expand Up @@ -47,7 +47,7 @@ public static class BooleanHelpers
/// <param name="dest">The destination array of integers.</param>
public unsafe static void ConvertToIntArray(Span<bool> array, byte* dest)
{
fixed(void* src = &array.DangerousGetPinnableReference())
fixed(void* src = array)
{
Unsafe.CopyBlockUnaligned(dest, src, (uint)array.Length);
}
Expand Down Expand Up @@ -93,7 +93,7 @@ public unsafe static void ConvertToIntArray(Span<bool> array, long* dest)
/// <param name="array">The target bool array to fill.</param>
public static unsafe void ConvertToBoolArray(byte* src, Span<bool> array)
{
fixed (void* dest = &array.DangerousGetPinnableReference())
fixed (void* dest = array)
{
Unsafe.CopyBlockUnaligned(dest, src, (uint)array.Length);
}
Expand Down
20 changes: 8 additions & 12 deletions SharpGen.Runtime/MemoryHelpers.cs
Expand Up @@ -60,16 +60,12 @@ public static void CopyMemory(IntPtr dest, IntPtr src, int sizeInBytesToCopy)
/// <param name="dest">The destination memory location.</param>
/// <param name="src">The source memory location.</param>
/// <param name="sizeInBytesToCopy">The byte count.</param>
public static void CopyMemory<T>(IntPtr dest, Span<T> src)
public static void CopyMemory<T>(IntPtr dest, ReadOnlySpan<T> src)
where T : struct
{
unsafe
{
var byteSpan = src.AsBytes();
fixed (void* source = &byteSpan[0])
{
Unsafe.CopyBlockUnaligned((void*)dest, source, (uint)byteSpan.Length);
}
src.CopyTo(new Span<T>((void*)dest, src.Length));
}
}

Expand All @@ -96,11 +92,11 @@ public static void ClearMemory(IntPtr dest, byte value, int sizeInBytesToClear)
/// <param name="offset">The offset in the array to write to.</param>
/// <param name="count">The number of T element to read from the memory location.</param>
/// <returns>source pointer + sizeof(T) * count.</returns>
public static IntPtr Read<T>(IntPtr source, T[] data, int offset, int count) where T : struct
public static IntPtr Read<T>(IntPtr source, T[] data, int offset, int count) where T : unmanaged
{
unsafe
{
return Read(source, new Span<T>(data).Slice(offset), count);
return Read(source, new ReadOnlySpan<T>(data).Slice(offset), count);
}
}

Expand All @@ -113,11 +109,11 @@ public static void ClearMemory(IntPtr dest, byte value, int sizeInBytesToClear)
/// <param name="offset">The offset in the array to write to.</param>
/// <param name="count">The number of T element to read from the memory location.</param>
/// <returns>source pointer + sizeof(T) * count.</returns>
public static IntPtr Read<T>(IntPtr source, Span<T> data, int count) where T : struct
public static IntPtr Read<T>(IntPtr source, ReadOnlySpan<T> data, int count) where T : unmanaged
{
unsafe
{
fixed (void* dataPtr = &data.AsBytes()[0])
fixed (void* dataPtr = data)
{
Unsafe.CopyBlockUnaligned(dataPtr, (void*)source, (uint)(count * Unsafe.SizeOf<T>()));
return source + Unsafe.SizeOf<T>() * count;
Expand All @@ -134,11 +130,11 @@ public static void ClearMemory(IntPtr dest, byte value, int sizeInBytesToClear)
/// <param name="offset">The offset in the array to read from.</param>
/// <param name="count">The number of T element to write to the memory location.</param>
/// <returns>destination pointer + sizeof(T) * count.</returns>
public static IntPtr Write<T>(IntPtr destination, Span<T> data, int count) where T : struct
public static IntPtr Write<T>(IntPtr destination, Span<T> data, int count) where T : unmanaged
{
unsafe
{
fixed (void* dataPtr = &data.AsBytes()[0])
fixed (void* dataPtr = data)
{
Unsafe.CopyBlockUnaligned((void*)destination, dataPtr, (uint)(count * Unsafe.SizeOf<T>()));
return destination + Unsafe.SizeOf<T>() * count;
Expand Down
6 changes: 3 additions & 3 deletions SharpGen.Runtime/SharpGen.Runtime.csproj
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard1.1;netstandard2.0</TargetFrameworks>
Expand All @@ -10,8 +10,8 @@
<ItemGroup>
<Content Include="Mapping.xml" PackagePath="build" />
<Content Include="SharpGen.Runtime.props" PackagePath="build;buildMultiTargeting" />
<PackageReference Include="System.Memory" Version="4.4.0-preview2-25405-01" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.4.0" />
<PackageReference Include="System.Memory" Version="4.5.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.5.0" />
<PackageReference Include="SourceLink.Create.CommandLine" Version="2.8.0" PrivateAssets="All" />
</ItemGroup>
</Project>

0 comments on commit 9d6092f

Please sign in to comment.