Are Delphi strings immutable?

▼魔方 西西 提交于 2019-12-01 05:12:26

Delphi strings are copy on write. If you modify a string (without using pointer tricks or similar techniques to fool the compiler), no other references to the same string will be affected.

Delphi strings are not interned. If you create the same string from two separate sections of code, they will not share the same backing store - the same data will be stored twice.

Delphi strings are not immutable (try: string1[2] := 'a') but they are reference-counted and copy-on-write.

The consequences for your hashes are not clear, you'll have to detail how they are stored etc.

But a hash should only depend on the contents of a string, not on how it is stored. That makes the whole question mute. Unless you can explain it better.

As others have said, Delphi strings are not generally immutable. Here are a few references on strings in Delphi.

http://blog.marcocantu.com/blog/delphi_super_duper_strings.html

http://conferences.codegear.com/he/article/32120

http://www.codexterity.com/delphistrings.htm

The Delphi version may be important to know. The good old Delphi BCL handles strings as copy-on-write, which basically means that a new instance is created when something in the string is changed. So yes, they are more or less immutable.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!