Discussion:
[fpc-pascal] FPC_PCHAR_LENGTH dog slow
Ryan Joseph
2018-07-03 15:15:16 UTC
Permalink
I was just parsing something and found that a call to length on a pchar was taking 90+% of the time in FPC_PCHAR_LENGTH.

Why is that so crazy slow? Does it need to iterate the entire length of the string to know it’s length?

Regards,
Ryan Joseph

_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman
Tomas Hajny
2018-07-03 16:01:05 UTC
Permalink
Post by Ryan Joseph
I was just parsing something and found that a call to
length on a pchar was taking 90+% of the time in
FPC_PCHAR_LENGTH.
Why is that so crazy slow? Does it need to iterate the
entire length of the string to know it’s length?
Yes, that's indeed the difference between Pascal strings
(Short/Ansi/Wide/UnicodeString) and C-like PChars.

Tomas


_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pasca
w***@windstream.net
2018-07-03 17:30:49 UTC
Permalink
Post by Tomas Hajny
Post by Ryan Joseph
Why is that so crazy slow? Does it need to iterate the entire length of the
string to know it’s length? >
Yes, that's indeed the difference between Pascal strings
(Short/Ansi/Wide/UnicodeString) and C-like PChars.
absolutely! i truly hated having to add loops to my string handling code when
working with ""C strings"" as we used to call them back in the day... the huge
advantage of "Pascal strings" is their length being specified at the beginning
of the character array they are stored in...

i think i'm still waiting for the string "length byte" becoming a "length word"
or possibly a "length long" so the speed of pascal strings can be reacquired -=B-)
--
NOTE: No off-list assistance is given without prior approval.
*Please keep mailing list traffic on the list unless*
*a signed and pre-paid contract is in effect with us.*
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.f
leledumbo via fpc-pascal
2018-07-03 17:44:01 UTC
Permalink
Post by w***@windstream.net
i think i'm still waiting for the string "length byte" becoming a "length word"
or possibly a "length long" so the speed of pascal strings can be reacquired
-=B-)

Ansi and any other dynamic strings already have length longint that allows
2GB string length with O(1) length retrieval.
w***@windstream.net
2018-07-03 18:09:44 UTC
Permalink
Post by leledumbo via fpc-pascal
Post by w***@windstream.net
i think i'm still waiting for the string "length byte" becoming a "length
word" or possibly a "length long" so the speed of pascal strings can be
reacquired -=B-) >
Ansi and any other dynamic strings already have length longint that allows
2GB string length with O(1) length retrieval.
excellent... i've been confused by all the various string changes that have been
made in the recent years since i joined the lists... the UTF stuff really spun
my head around with all the various discussions and arguments... i'm still not
sure i understand it... i don't need UTF but i hope that my newer programs are
written properly to handle UTF if it ever comes up... they're generally console
applications reading textual data from elsewhere and processing for local output...
--
NOTE: No off-list assistance is given without prior approval.
*Please keep mailing list traffic on the list unless*
*a signed and pre-paid contract is in effect with us.*
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/
Mattias Gaertner
2018-07-03 16:01:00 UTC
Permalink
On Tue, 3 Jul 2018 09:15:16 -0600
Post by Ryan Joseph
I was just parsing something and found that a call to length on a pchar was taking 90+% of the time in FPC_PCHAR_LENGTH.
Why is that so crazy slow? Does it need to iterate the entire length of the string to know it’s length?
Yes.

Mattias
_______________________________________________
fpc-pascal maillist - fpc-***@lists.freepascal.org
http://lists.freepas
Loading...