Skip to content

Commit

Permalink
Added comments for better description of the decisions made about imp…
Browse files Browse the repository at this point in the history
…lementation.
  • Loading branch information
Konard committed Oct 31, 2019
1 parent 06f3948 commit 663b041
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Platform.Unsafe/MemoryBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ public static unsafe class MemoryBlock
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Zero(void* pointer, long capacity)
{
// A way to prevent wasting resources due to Hyper-threading.
var threads = Environment.ProcessorCount / 2;
if (threads <= 1)
{
InitBlock(pointer, 0, (uint)capacity);
}
else
{
// Using 2 threads, because two-channel memory architecture is the most available type.
// CPUs are mostly just wait for memory here.
threads = 2;
Parallel.ForEach(Partitioner.Create(0L, capacity), new ParallelOptions { MaxDegreeOfParallelism = threads }, range => ZeroBlock(pointer, range.Item1, range.Item2));
}
Expand Down

0 comments on commit 663b041

Please sign in to comment.