什么时候和为什么要使用TStringBuilder? [英] When and Why Should I Use TStringBuilder?

查看:132
本文介绍了什么时候和为什么要使用TStringBuilder?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一年前,我将程序从Delphi 4转换为Delphi 2009,主要是为了跳转到Unicode,也可以获得所有这些年Delphi改进的好处。



我的代码当然是所有遗留代码。它使用的短字符串现在方便地都变成长Unicode字符串,我已经将所有旧的ANSI函数更改为新的等价物。



但是使用Delphi 2009介绍了TStringBuilder类,大概是在.NETBuilder类之后建模的。



我的程序执行了大量的字符串处理和操作,可以加载数百兆字节的大字符串一次进入内存使用。



我不太了解Delphi的TStringBuilder的实现,但我听说其中的一些操作比使用默认字符串操作。



我的问题是,我是否值得我努力,并将我的标准字符串转换为使用TStringBuilder类。我会得到和损失的是什么?






感谢您的回答,并引导我得出结论,这是不要麻烦,除非需要.NET兼容性。



在他的博客上德尔福2009年String性能,Jolyon Smith说


但是看起来好像TStringBuilder主要是以.NET兼容夹具,而不是为Win32应用程序的开发人员提供任何真正的好处,除了开发人员希望或需要单个源代码不支持字符串处理性能的Win32 / .NET代码库之外。



解决方案

据我所知,TStringBuilder只是为了与.NET和Java的一致性而被介绍,似乎是更多的是选择框类型功能比任何主要进展。



共识似乎是TStringBuilder在一些操作中更快,但在其他操作中更慢。



您的程序听起来像一个有趣的在TStringBuilder之前/之后进行比较,但我不会做,除了作为一个学术活动。


I converted my program from Delphi 4 to Delphi 2009 a year ago, mainly to make the jump to Unicode, but also to gain the benefits of all those years of Delphi improvements.

My code, of course, is therefore all legacy code. It uses short strings that have now conveniently all become long Unicode strings, and I've changed all the old ANSI functions to the new equivalent.

But with Delphi 2009, they introduced the TStringBuilder class, presumably modelled after the StringBuilder class of .NET.

My program does a lot of string handling and manipulation, and can load hundreds of megabytes of large strings into memory at once to work with.

I don't know a lot about Delphi's implementation of TStringBuilder, but I heard that some of its operations are faster than using the default string operations.

My question is whether or not it is worthwhile for me to go through the effort and convert my standard strings to use the TStringBuilder class. What would I gain and lose from doing that?


Thank you for your answers and leading me to my conclusion, which is not to bother unless .NET compatibility is required.

On his blog on Delphi 2009 String Performance, Jolyon Smith states:

But it looks to me as if TStringBuilder is there primarily as a .NET compatibility fixture, rather than to provide any real benefit to developers of Win32 applications, with the possible exception of developers wishing or needing to single-source a Win32/.NET codebase where string handling performance isn’t a concern.

解决方案

To the best of my knowledge TStringBuilder was introduced just for some parity with .NET and Java, it seems to be more of a tick the box type feature than any major advance.

Consensus seems to be that TStringBuilder is faster in some operations but slower in others.

Your program sounds like an interesting one to do a before/after TStringBuilder comparison with but I wouldn't do it other than as an academic exercise.

这篇关于什么时候和为什么要使用TStringBuilder?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆