Skip to content

Commit 9572796

Browse files
committed
0.6.3: Fixed memory allocation for size >= 2GB
1 parent d710daa commit 9572796

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/ZstdSharp/UnsafeHelper.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace ZstdSharp
1414
{
1515
public static unsafe class UnsafeHelper
1616
{
17-
public static void* PoisonMemory(void* destination, int size)
17+
public static void* PoisonMemory(void* destination, ulong size)
1818
{
1919
memset(destination, 0xCC, size);
2020
return destination;
@@ -24,7 +24,7 @@ public static unsafe class UnsafeHelper
2424
public static void* malloc(uint size)
2525
{
2626
#if DEBUG
27-
return PoisonMemory((void*)Marshal.AllocHGlobal((int)size), (int)size);
27+
return PoisonMemory((void*)Marshal.AllocHGlobal((int)size), size);
2828
#else
2929
return (void*) Marshal.AllocHGlobal((int) size);
3030
#endif
@@ -34,19 +34,17 @@ public static unsafe class UnsafeHelper
3434
public static void* malloc(ulong size)
3535
{
3636
#if DEBUG
37-
return PoisonMemory((void*)Marshal.AllocHGlobal((int)size), (int)size);
37+
return PoisonMemory((void*) Marshal.AllocHGlobal((nint) size), size);
3838
#else
39-
return (void*)Marshal.AllocHGlobal((int)size);
39+
return (void*) Marshal.AllocHGlobal((nint) size);
4040
#endif
4141
}
4242

4343
[MethodImpl(MethodImplOptions.AggressiveInlining)]
4444
public static void* calloc(ulong num, ulong size)
4545
{
46-
int total = (int)(num * size);
47-
var destination = (void*)Marshal.AllocHGlobal(total);
48-
//Unsafe.InitBlockUnaligned(destination, 0, (uint)total);
49-
//Ldloc(nameof(destination));
46+
var total = num * size;
47+
var destination = (void*) Marshal.AllocHGlobal((nint) total);
5048
memset(destination, 0, total);
5149
return destination;
5250
}

src/ZstdSharp/ZstdSharp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageProjectUrl>https://github.com/oleg-st/ZstdSharp</PackageProjectUrl>
1515
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
1616
<PackageTags>zstd zstandard port compression</PackageTags>
17-
<Version>0.6.2</Version>
17+
<Version>0.6.3</Version>
1818
</PropertyGroup>
1919

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

0 commit comments

Comments
 (0)