Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions csharp/sbe-dll/DirectBuffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public int Capacity
{
get { return _capacity; }
}

/// <summary>
/// Check that a given limit is not greater than the capacity of a buffer from a given offset.
/// </summary>
Expand All @@ -129,17 +129,22 @@ public void CheckLimit(int limit)
{
if (limit > _capacity)
{
if (bufferOverflow == null)
throw new IndexOutOfRangeException(string.Format("limit={0} is beyond capacity={1}", limit, _capacity));
TryResizeBuffer(limit);
}
}

var newBuffer = bufferOverflow(_capacity, limit);
private void TryResizeBuffer(int limit)
{
if (bufferOverflow == null)
throw new IndexOutOfRangeException(string.Format("limit={0} is beyond capacity={1}", limit, _capacity));

if (newBuffer == null)
throw new IndexOutOfRangeException(string.Format("limit={0} is beyond capacity={1}", limit, _capacity));
var newBuffer = bufferOverflow(_capacity, limit);

Marshal.Copy((IntPtr)_pBuffer, newBuffer, 0, _capacity);
Wrap(newBuffer);
}
if (newBuffer == null)
throw new IndexOutOfRangeException(string.Format("limit={0} is beyond capacity={1}", limit, _capacity));

Marshal.Copy((IntPtr)_pBuffer, newBuffer, 0, _capacity);
Wrap(newBuffer);
}

/// <summary>
Expand Down