Skip to content

Commit

Permalink
0.6.3: Fixed memory allocation for size >= 2GB
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-st committed Aug 14, 2022
1 parent d710daa commit 9572796
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
14 changes: 6 additions & 8 deletions src/ZstdSharp/UnsafeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace ZstdSharp
{
public static unsafe class UnsafeHelper
{
public static void* PoisonMemory(void* destination, int size)
public static void* PoisonMemory(void* destination, ulong size)
{
memset(destination, 0xCC, size);
return destination;
Expand All @@ -24,7 +24,7 @@ public static unsafe class UnsafeHelper
public static void* malloc(uint size)
{
#if DEBUG
return PoisonMemory((void*)Marshal.AllocHGlobal((int)size), (int)size);
return PoisonMemory((void*)Marshal.AllocHGlobal((int)size), size);
#else
return (void*) Marshal.AllocHGlobal((int) size);
#endif
Expand All @@ -34,19 +34,17 @@ public static unsafe class UnsafeHelper
public static void* malloc(ulong size)
{
#if DEBUG
return PoisonMemory((void*)Marshal.AllocHGlobal((int)size), (int)size);
return PoisonMemory((void*) Marshal.AllocHGlobal((nint) size), size);
#else
return (void*)Marshal.AllocHGlobal((int)size);
return (void*) Marshal.AllocHGlobal((nint) size);
#endif
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void* calloc(ulong num, ulong size)
{
int total = (int)(num * size);
var destination = (void*)Marshal.AllocHGlobal(total);
//Unsafe.InitBlockUnaligned(destination, 0, (uint)total);
//Ldloc(nameof(destination));
var total = num * size;
var destination = (void*) Marshal.AllocHGlobal((nint) total);
memset(destination, 0, total);
return destination;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ZstdSharp/ZstdSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageProjectUrl>https://github.com/oleg-st/ZstdSharp</PackageProjectUrl>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageTags>zstd zstandard port compression</PackageTags>
<Version>0.6.2</Version>
<Version>0.6.3</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down

0 comments on commit 9572796

Please sign in to comment.