Skip to content

Commit

Permalink
fix #241 (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgravell committed Apr 8, 2024
1 parent 5675a98 commit dc1ff66
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ internal override void AllocatePage(int index)

byte[] tmp = GC.AllocateArray<byte>(adjustedSize, true);
long p = (long)Unsafe.AsPointer(ref tmp[0]);
Array.Clear(tmp, 0, adjustedSize);
pointers[index] = (p + (sectorSize - 1)) & ~((long)sectorSize - 1);
values[index] = tmp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public unsafe void Allocate(int index)

byte[] tmp = GC.AllocateArray<byte>(adjustedSize, true);
long p = (long)Unsafe.AsPointer(ref tmp[0]);
Array.Clear(tmp, 0, adjustedSize);
pointers[index] = (p + (sectorSize - 1)) & ~((long)sectorSize - 1);
frame[index] = tmp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,7 @@ internal override void AllocatePage(int index)
if (overflowPagePool.TryGet(out var item))
return item;

Record<Key, Value>[] tmp;
if (PageSize % RecordSize == 0)
tmp = new Record<Key, Value>[PageSize / RecordSize];
else
tmp = new Record<Key, Value>[1 + (PageSize / RecordSize)];
Array.Clear(tmp, 0, tmp.Length);
return tmp;
return new Record<Key, Value>[(PageSize + RecordSize - 1) / RecordSize];
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
8 changes: 1 addition & 7 deletions libs/storage/Tsavorite/cs/src/core/Allocator/GenericFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ public GenericFrame(int frameSize, int pageSize)

public void Allocate(int index)
{
Record<Key, Value>[] tmp;
if (pageSize % RecordSize == 0)
tmp = new Record<Key, Value>[pageSize / RecordSize];
else
tmp = new Record<Key, Value>[1 + (pageSize / RecordSize)];
Array.Clear(tmp, 0, tmp.Length);
frame[index] = tmp;
frame[index] = new Record<Key, Value>[(pageSize + RecordSize - 1) / RecordSize];
}

public void Clear(int pageIndex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

#pragma warning disable 0162

#define CALLOC

using System;
using System.Collections.Concurrent;
using System.Diagnostics;
Expand Down Expand Up @@ -113,10 +111,6 @@ public unsafe MallocFixedPageSize(ILogger logger = null)
pointers[0] = (IntPtr)(((long)Unsafe.AsPointer(ref values[0][0]) + (SectorSize - 1)) & ~(SectorSize - 1));
}

#if !(CALLOC)
Array.Clear(values[0], 0, PageSize);
#endif

writeCacheLevel = -1;
Interlocked.MemoryBarrier();

Expand Down Expand Up @@ -236,9 +230,6 @@ private unsafe long InternalAllocate(int blockSize)
if (IsBlittable)
pointers[1] = (IntPtr)(((long)Unsafe.AsPointer(ref tmp[0]) + (SectorSize - 1)) & ~(SectorSize - 1));

#if !(CALLOC)
Array.Clear(tmp, 0, PageSize);
#endif
values[1] = tmp;
Interlocked.MemoryBarrier();
}
Expand Down Expand Up @@ -287,9 +278,6 @@ private unsafe long InternalAllocate(int blockSize)
if (IsBlittable)
pointers[newBaseAddr] = (IntPtr)(((long)Unsafe.AsPointer(ref tmp[0]) + (SectorSize - 1)) & ~(SectorSize - 1));

#if !(CALLOC)
Array.Clear(tmp, 0, PageSize);
#endif
values[newBaseAddr] = tmp;

Interlocked.MemoryBarrier();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ internal override void AllocatePage(int index)

byte[] tmp = GC.AllocateArray<byte>(adjustedSize, true);
long p = (long)Unsafe.AsPointer(ref tmp[0]);
Array.Clear(tmp, 0, adjustedSize);
pointers[index] = (p + (sectorSize - 1)) & ~((long)sectorSize - 1);
values[index] = tmp;
}
Expand Down

0 comments on commit dc1ff66

Please sign in to comment.