private static byte[] Allocate( byte[] old, int requestSize )
{
if ( old.Length < 256 )
{
return new byte[ 256 ];
}
// Use golden ratio to improve linear memory range reusability (of LOH)
var newSize = Math.Max( ( long )( old.Length * 1.1618 ), requestSize + ( long )old.Length );
if ( newSize > Int32.MaxValue )
{
return null;
}
return new byte[ newSize ];
}
May be instead of
if ( old.Length < 256 )
should be
if (requestSize < 256 )
Because if requested buffer size is greater than 256 and current buffer's length is less than 256 (for example we just serialize big string), then we fail to allocate, and whole serialization process will fail ...
May be instead of
should be
Because if requested buffer size is greater than 256 and current buffer's length is less than 256 (for example we just serialize big string), then we fail to allocate, and whole serialization process will fail ...