springtg / lidgren-network-gen3

Automatically exported from code.google.com/p/lidgren-network-gen3
0 stars 0 forks source link

m_bytesAllocated does not include resized buffers #114

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Inside NetPeer.GetStorage 

m_statistics.m_bytesAllocated += minimumCapacity;

Then in NetBuffer.EnsureBufferSize the byte array can be resized which will 
cause an allocation of an entirely new array of the new length. This 
reallocation should be added to the statistics. Suggested code below.

It may be worth a new statistic to see how many times the buffer is resized too.

public void EnsureBufferSize(int numberOfBits)
{
  int byteLen = ((numberOfBits + 7) >> 3);
  if (m_data == null)
  {
    m_data = new byte[byteLen + c_overAllocateAmount];
    m_statistics.m_bytesAllocated += byteLen + c_overAllocateAmount;
    return;
  }
  if (m_data.Length < byteLen)
  {
    Array.Resize<byte>(ref m_data, byteLen + c_overAllocateAmount);
    m_statistics.m_bytesAllocated += byteLen + c_overAllocateAmount;
  }
  return;
}

Original issue reported on code.google.com by z...@thezbuffer.com on 4 Apr 2012 at 4:19

GoogleCodeExporter commented 9 years ago
Unfortunately m_statistics is not available in the NetBuffer class (or derived 
classes NetIncomingMessage) so I'm unsure how to add this properly. I'll keep 
investigating.

Original comment by lidg...@gmail.com on 26 May 2012 at 8:24