Skip to content

Commit efc51ae

Browse files
committed
Code cleanup
1 parent 0317dd3 commit efc51ae

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/DotNext.Unsafe/Buffers/UnmanagedMemory.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ internal static void Discard(nint address, nint length)
290290

291291
if (!IsPageAligned(length))
292292
throw new ArgumentOutOfRangeException(nameof(length));
293-
293+
294294
if (VirtualMemoryManagementFunc is 0)
295295
return;
296296

@@ -300,18 +300,20 @@ internal static void Discard(nint address, nint length)
300300
const int MADV_DONTNEED = 4;
301301

302302
var madvise = (delegate*unmanaged<nint, nint, int, int>)VirtualMemoryManagementFunc;
303-
304303
errorCode = madvise(address, length, MADV_DONTNEED);
305-
if (errorCode is not 0)
306-
throw new ExternalException(ExceptionMessages.UnableToDiscardMemory, errorCode);
307304
}
308305
else if (OperatingSystem.IsWindows())
309306
{
310307
var discardVirtualMemory = (delegate*unmanaged<nint, nint, int>)VirtualMemoryManagementFunc;
311308
errorCode = discardVirtualMemory(address, length);
312-
if (errorCode is not 0)
313-
throw new Win32Exception(errorCode, ExceptionMessages.UnableToDiscardMemory);
314309
}
310+
else
311+
{
312+
errorCode = 0;
313+
}
314+
315+
if (errorCode is not 0)
316+
throw new ExternalException(ExceptionMessages.UnableToDiscardMemory, errorCode);
315317
}
316318

317319
protected override void Dispose(bool disposing)

0 commit comments

Comments
 (0)