On Wed, 1 Mar 2006 21:35:54 +0100 (Romance Standard Time) Michael Van Canneyt <[EMAIL PROTECTED]> wrote:
> > > On Wed, 1 Mar 2006, L505 wrote: > > > > > > > On Wed, 1 Mar 2006, L505 wrote: > > > > > > > > > Widestrings need to be like that for compatibility with c and > > > > > > c++ > > > > > > > > > Not exactly, they need to be like this because the dang MS COM. > > > > > However I can't see why is this different than the AnsiString vs > > > > > Windows PChar-based API... > > > > > > > > > > > > I'm off topic here but: > > > > I think there should be a standard reference counting mechanism > > > > (standards comittee?) between language. We have the standard ansi > > > > string header > > embedded in > > > > the ansistring but no standard reference counting mechanism. If this > > > > was the case we could share our ansi strings in DLL's with C++ and > > > > other languages. > > > > > > Ansistrings are unique to Object Pascal. The implementation of strings > > > in C++ is completely different. > > > > > > > However There are good reasons for using pchars especially during > > > > string concatenations - ansistrings are dead slow when you are > > > > making tons of small concatenations. > > > > > > Sorry, but that is total nonsense. Not more than 'naive' pchars. > > > > > > > My strloadfile benchmark proves that the standard programmer using > > simple concatenations with ansistrings will have a serious speed problem > > in his application. > > Exactly my point. The C programmer just already allocates enough > memory to start with. If he would do a getmem/freemem/strcat each time, > his application would be just as slow as a Pascal program. > > Only as a C programmer he is used to this kind of thinking... > > Pascal has the best of both worlds: you can use the 'simple' way, > for fast coding, but you can also use the 'complicated' but faster, way. > > Usually I start with a 'simple' straightforward implementation > for fast coding. and when speed really becomes an issue, I change > it to the complicated way... > > > > > Unless you have in depth knowledge about how every bit of ansistring > > memory management works, using getmem and freemem and pchars are > > simpler, no? Because you are not battling the automatic memory > > management. Now, if you are an expert in battling the automatic memory > > management maybe you can battle ansistrings enough to be almost or just > > as fast as pchars. Is this what we are doing in the fpc sources? I will > > have to look, and see. > > Yes. For example: The codetools use ansistrings. Less than 1% use PChars. Just avoid the + operator as you would avoid ReAllocMem and StrCopy. > > Does it require some simple setlength calls or is it more complex than > > that? > > Simple setlength will do. > > > Does it require less or more lines of code than simply using getmem and > > freemem? > > Less. The setlength takes care of it for you. That is the whole point. > > > I bet you end up inserting lots more lines of code to battle the memory > > manager instead of just manually taking control of it yourself. > > No. > The setlength also provides automatic correct terminating and so on, > plus you always have the length stored correctly. Not so with > getmem/freemem. Mattias _________________________________________________________________ To unsubscribe: mail [EMAIL PROTECTED] with "unsubscribe" as the Subject archives at http://www.lazarus.freepascal.org/mailarchives