 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Avatar Zondertau Guest
|
Posted: Sun Mar 13, 2005 1:01 pm Post subject: Re: AnsiString and #0 |
|
|
| Quote: | I was just looking at the FastCode tests for StringReplace.
First thing which seemed odd is that the RTL code failed the tests.
The next thing which struck me as odd is that some tests were like so
#0 + 'a';
yet it would seem that AnsiString truncates strings at #0, so this
cannot be valid. Am I wrong, I'm confused by the tests.
|
There's a difference between PAnsiChar and AnsiString.
The former is #0-terminated and is an exact replica of char* in C++.
The latter is more complex. Delphi keeps track of it's length in a
special field (stored in a DWORD directly before the start of the
string) and takes care of it's memory management, including reference
counting and copy-on-write. Because AnsiStrings explicitly store their
length, their length can be more efficiently determined and they can
have #0 characters inside them. To avoid C++ compatibility problems
Delphi also adds a #0 after the last char of the string, so if it's
cast to a PAnsiChar it will still be valid. This #0 should however not
be used by Delphi itself.
The RTL StringReplace function is buggy, because it casts the
AnsiString to a PAnsiString, forgetting it's actual length, but using
the #0 terminator instead. This bug has been reported to QC:
http://qc.borland.com/wc/qcmain.aspx?d=11265
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|