/// <summary> /// 如果外部能够提供缓冲区则使用外部缓冲区,否则new byte[] /// </summary> /// <param name="needSize"></param> /// <returns></returns> internal protected BufferOwner CreateBuffer(int needSize) { var res = callbackHandle?.RentBuffer(needSize); if (res == null) { return(new KcpInnerBuffer(needSize)); } else { if (res.Memory.Length < needSize) { throw new ArgumentException($"{nameof(callbackHandle.RentBuffer)} 指定的委托不符合标准,返回的" + $"BufferOwner.Memory.Length 小于 {nameof(needSize)}"); } } return(res); }
/// <summary> /// 如果外部能够提供缓冲区则使用外部缓冲区,否则new byte[] /// </summary> /// <param name="size"></param> /// <returns></returns> public BufferOwner CreateBuffer(int size) { var res = callbackHandle?.RentBuffer(size); if (res == null) { return(new KCPInnerBuffer(size)); } else { if (res.Memory.Length != size) { throw new ArgumentException($"{nameof(callbackHandle.RentBuffer)} 指定的委托不符合标准,返回的" + $"BufferOwner.Memory.Length 与 needLenght 不一致"); } } return(res); }