Re: [fpc-devel] PShortString

2010-09-10 Thread Daniël Mantione



Op Fri, 10 Sep 2010, schreef Hans-Peter Diettrich:


Sergei Gorelkin schrieb:

When dynamic strings are used all around, is the use of pointers to 
ShortString still recommended? (fmodule contains a lot of them)


Whenever you care about performance, you'll quickly realize that dynamic 
strings are plain inappropriate.


The concrete use of PShortString strings is inappropriate in your sense, 
because it results in allocation, copy and deallocation of temporary strings 
in the code, in many places. This behaviour gave birth to my question.


Ansistrings result allocation copy and deallocation during *processing*. 
The use of ansistrings would make the compiler at least twice as slow and 
quadruple its memory consumption.


Daniël___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] PShortString

2010-09-10 Thread Florian Klaempfl
Am 10.09.2010 02:41, schrieb Hans-Peter Diettrich:
 Florian Klaempfl schrieb:
 
 1. Ancient code, keep in mind, most code not being back end code was
 written ~10 years ago. At this time we even could not depend on
 perfectly working ansistrings.
 
 I'm talking about nowadays situation.

You asked for reasons why it is done as it is done.

 
 2. Ansistring create an explicit exception frame etc. which slows down
 things.
 
 Also when the strings are const parameters, as they are in this case?

If there is no other use, no. But if there is any processing or just a
local ansistring: yes.
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] PShortString

2010-09-10 Thread Sergei Gorelkin

Daniël Mantione пишет:



Op Fri, 10 Sep 2010, schreef Hans-Peter Diettrich:


Sergei Gorelkin schrieb:

When dynamic strings are used all around, is the use of pointers to 
ShortString still recommended? (fmodule contains a lot of them)


Whenever you care about performance, you'll quickly realize that 
dynamic strings are plain inappropriate.


The concrete use of PShortString strings is inappropriate in your 
sense, because it results in allocation, copy and deallocation of 
temporary strings in the code, in many places. This behaviour gave 
birth to my question.


Ansistrings result allocation copy and deallocation during *processing*. 
The use of ansistrings would make the compiler at least twice as slow 
and quadruple its memory consumption.


Also, don't forget that an AnsiString assignment, even when it doen not end up in memory 
allocations, will execute two intelocked instructions in multithreaded process.



Regards,
Sergei
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


[fpc-devel] PShortString

2010-09-09 Thread Hans-Peter Diettrich
When dynamic strings are used all around, is the use of pointers to 
ShortString still recommended? (fmodule contains a lot of them)


In many cases (almost all I found) the strings are duplicated when 
assigned, because the given dynamic strings disallow to simply copy the 
reference.


IMO P[Short]Strings only were useful when the referenced string shall be 
changed later, with that change reflected automatically in all 
references. Since this seems not to occur anywhere, I'd suggest to 
replace or retype PShortString by [Ansi]String.


DoDi

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] PShortString

2010-09-09 Thread Florian Klaempfl
Am 09.09.2010 15:52, schrieb Hans-Peter Diettrich:
 When dynamic strings are used all around, is the use of pointers to
 ShortString still recommended? (fmodule contains a lot of them)

1. Ancient code, keep in mind, most code not being back end code was
written ~10 years ago. At this time we even could not depend on
perfectly working ansistrings.
2. Ansistring create an explicit exception frame etc. which slows down
things.

Due to the explicit exception frame generation, I would propose not to
change it but only if the length limitation is a problem.

 
 In many cases (almost all I found) the strings are duplicated when
 assigned, because the given dynamic strings disallow to simply copy the
 reference.
 
 IMO P[Short]Strings only were useful when the referenced string shall be
 changed later, with that change reflected automatically in all
 references. Since this seems not to occur anywhere, I'd suggest to
 replace or retype PShortString by [Ansi]String.
 
 DoDi
 
 ___
 fpc-devel maillist  -  fpc-devel@lists.freepascal.org
 http://lists.freepascal.org/mailman/listinfo/fpc-devel
 

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] PShortString

2010-09-09 Thread Sergei Gorelkin

Hans-Peter Diettrich wrote:
When dynamic strings are used all around, is the use of pointers to 
ShortString still recommended? (fmodule contains a lot of them)


Whenever you care about performance, you'll quickly realize that dynamic strings are plain 
inappropriate. When it is also known that 255 character limit won't be exceeded, ShortString is 
nearly an ideal choice.


In many cases (almost all I found) the strings are duplicated when 
assigned, because the given dynamic strings disallow to simply copy the 
reference.


IMO P[Short]Strings only were useful when the referenced string shall be 
changed later, with that change reflected automatically in all 
references. Since this seems not to occur anywhere, I'd suggest to 
replace or retype PShortString by [Ansi]String.


They provide fine-grained control over memory allocations, avoiding implicit try..finally blocks and 
memory allocations for temps. Copying still occurs, but with the highly optimized Move procedure it 
is pretty cheap. So please don't change such things just because something is used all around.


Regards,
Sergei
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] PShortString

2010-09-09 Thread Hans-Peter Diettrich

Sergei Gorelkin schrieb:

When dynamic strings are used all around, is the use of pointers to 
ShortString still recommended? (fmodule contains a lot of them)


Whenever you care about performance, you'll quickly realize that dynamic 
strings are plain inappropriate.


The concrete use of PShortString strings is inappropriate in your sense, 
because it results in allocation, copy and deallocation of temporary 
strings in the code, in many places. This behaviour gave birth to my 
question.



They provide fine-grained control over memory allocations, avoiding 
implicit try..finally blocks and memory allocations for temps. Copying 
still occurs, but with the highly optimized Move procedure it is pretty 
cheap. So please don't change such things just because something is 
used all around.


All that would no more be needed after a decent redesign. Or the 
existing code is inappropriate, and all the mentioned operations can be 
removed from the source code, without affecting the behaviour and result.


DoDi

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] PShortString

2010-09-09 Thread Hans-Peter Diettrich

Florian Klaempfl schrieb:


1. Ancient code, keep in mind, most code not being back end code was
written ~10 years ago. At this time we even could not depend on
perfectly working ansistrings.


I'm talking about nowadays situation.


2. Ansistring create an explicit exception frame etc. which slows down
things.


Also when the strings are const parameters, as they are in this case?

DoDi

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel