Skip to content

Commit

Permalink
Removing extra buffer copy
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfreiling committed Apr 4, 2019
1 parent f41f1e8 commit b78aee3
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions cs/src/core/Allocator/GenericAllocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,26 @@ protected override void ClearPage(long page)

if (ms.Position > ObjectBlockSize || i == (end / recordSize) - 1)
{
var memoryStreamLength = (int)ms.Position;

var _objBuffer = bufferPool.Get(memoryStreamLength);

asyncResult.done = new AutoResetEvent(false);

var _alignedLength = (memoryStreamLength + (sectorSize - 1)) & ~(sectorSize - 1);

var _objAddr = Interlocked.Add(ref localSegmentOffsets[(long)(alignedDestinationAddress >> LogSegmentSizeBits) % SegmentBufferSize], _alignedLength) - _alignedLength;
fixed (void* src_ = ms.GetBuffer())
Buffer.MemoryCopy(src_, _objBuffer.aligned_pointer, memoryStreamLength, memoryStreamLength);

foreach (var address in addr)
((AddressInfo*)address)->Address += _objAddr;

if (KeyHasObjects())
keySerializer.EndSerialize();
if (ValueHasObjects())
valueSerializer.EndSerialize();
var _s = ms.ToArray();

ms.Close();

if (i < (end / recordSize) - 1)
Expand All @@ -382,23 +397,7 @@ protected override void ClearPage(long page)
keySerializer.BeginSerialize(ms);
if (ValueHasObjects())
valueSerializer.BeginSerialize(ms);
}

var _objBuffer = bufferPool.Get(_s.Length);

asyncResult.done = new AutoResetEvent(false);

var _alignedLength = (_s.Length + (sectorSize - 1)) & ~(sectorSize - 1);

var _objAddr = Interlocked.Add(ref localSegmentOffsets[(long)(alignedDestinationAddress >> LogSegmentSizeBits) % SegmentBufferSize], _alignedLength) - _alignedLength;
fixed (void* src_ = _s)
Buffer.MemoryCopy(src_, _objBuffer.aligned_pointer, _s.Length, _s.Length);

foreach (var address in addr)
((AddressInfo*)address)->Address += _objAddr;

if (i < (end / recordSize) - 1)
{
objlogDevice.WriteAsync(
(IntPtr)_objBuffer.aligned_pointer,
(int)(alignedDestinationAddress >> LogSegmentSizeBits),
Expand Down

0 comments on commit b78aee3

Please sign in to comment.