support GetMemory()

pull/19792/head
Jan Tattermusch 6 years ago
parent 891dc61d8e
commit fb5411fba9
  1. 13
      src/csharp/Grpc.Core/Internal/SliceBufferSafeHandle.cs

@ -39,6 +39,8 @@ namespace Grpc.Core.Internal
private IntPtr tailSpacePtr;
private int tailSpaceLen;
private SliceMemoryManager memoryManagerLazy;
private SliceBufferSafeHandle()
{
}
@ -63,14 +65,20 @@ namespace Grpc.Core.Internal
GrpcPreconditions.CheckArgument(tailSpaceLen >= count);
tailSpaceLen = tailSpaceLen - count;
tailSpacePtr += count;
memoryManagerLazy?.Reset();
}
// provides access to the "tail space" of this buffer.
// Use GetSpan when possible for better efficiency.
public Memory<byte> GetMemory(int sizeHint = 0)
{
// TODO: implement
throw new NotImplementedException();
GetSpan(sizeHint);
if (memoryManagerLazy == null)
{
memoryManagerLazy = new SliceMemoryManager();
}
memoryManagerLazy.Reset(new Slice(tailSpacePtr, tailSpaceLen));
return memoryManagerLazy.Memory;
}
// provides access to the "tail space" of this buffer.
@ -97,6 +105,7 @@ namespace Grpc.Core.Internal
// deletes all the data in the slice buffer
tailSpacePtr = IntPtr.Zero;
tailSpaceLen = 0;
memoryManagerLazy?.Reset();
Native.grpcsharp_slice_buffer_reset_and_unref(this);
}

Loading…
Cancel
Save