English 中文(简体)
StringBuilder或 +=
原标题:StringBuilder or +=

我收到约5份电文。 每一个政党都有一席之地,我认为这是一席之地,载有所有收到的信息。

    string _masterText = "";
    public void AddNewMessage(string text)  // this is going to be call at least 5 times/second
    {
        _masterText += text;    
    }

这样做的时机是否成熟? 或者,我应该使用“强硬”,例如:

    StringBuilder _masterText = new StringBuilder();
    public void AddNewMessage(string text) // this is going to be call at least 5 times/second
    {
         _masterText.Append(text);  
    }

增 编

最佳回答

StringBuilder一般被认为是更好的选择,但在此情况下,I d Use neither.

即使与StingBuilder一样,按这一比率计算,基本特性的缓冲很快将足够大,无法在大目标海普上 st。 这会给申请的健康带来问题,而申请需要停留一段时间。

相反,我使用的是<代码>System.Collections.Generic.List<string>,并且仅指每个新电文的.Add(方法。 根据你对这些电文的掌握情况,你还可以发现另一种收集类型更为合适(或许是Queue<string>),但这是你应该走的方向。 通过收集,每个方位所用的记忆不会达到收集标的大小。 相反,每条插图只能添加几个字句,以供参考。 这将需要很长的时间才能解决大目标“大目标”。

如果您在转向收集后仍然有问题,你可使用stream<>em>,并用纸面打印。 这样一来,在援助团中,你从未有过过过一次。 现在,如果个人扼杀是85,000英特或大于85,000英特,你唯一会遇到问题的办法。

问题回答

考虑到<代码>String类别不可更改。 不可能改变扼杀。 当你是“策划”时,你真的会造一个新雕像,并抄录原插图的内容,然后添加你新写的内容。

如果你重新评价大范围布局,这开始非常迅速地使用记忆。

每200人都有一次非常征税的投票,无论哪怕是扼杀手,情况总是较好。

页: 1

这还取决于具体情况。 无疑,比固醇物体更快地增加通用清单。 但是,在从通用清单检索数据时,与强硬物体相比,数据会慢得多。

护卫员将迅速使用主机Text.ToString(......)返回,但用通用名单,你可能不得不利用电梯来拉价值。 这将是昂贵的过程,例如:

  for (int x = 0; x < 100; x++)
    {
      Label3.Text += gen_list[x];
    }

或你可以尝试

Label3.Text = string.Join("), gen_list.ToArray();

之后,回收作业将比较缓慢和昂贵,而且你可以很容易地注意到CPU的激增。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...