BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Re: AnsiString and #0

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM
View previous topic :: View next topic  
Author Message
Avatar Zondertau
Guest





PostPosted: Sun Mar 13, 2005 1:01 pm    Post subject: Re: AnsiString and #0 Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.