Hallo Martin,

Du schriebst am Fri, 13 Apr 2012 08:10:15 +0200:

> > That's nonsense. Implemented correctly, _any_ index base gives identical
> > speed - you _don't_ implement it using offset calculation from the first
...
> You probably should have a look into the disassembler listings of your 
> programs and the FPC RTL.

That was not a description of the actual implementation by FPC, but one
giving the "state of the art" (a very old art, indeed, as it was common
knowledge half a century ago - not longer though, it seems?).

> Why do you think Pascal string index is one based in the first place?
> Because it is a zero based index to the old shortstring data where
> <shortstring>[0] denotes the length byte, do you remember?

I _know_ this, as I used this over and over for getting and setting the
length of strings in Tubo Pascal, until around version 6 it was
"deprecated" (as it's called today) and replaced by "SetLength" for
setting - getting was always possible by the "Length" function.
But the original justification for the indexing scheme was said to be that
the actually used character data should be counted "naturally", starting at
1, and the "0th" element was simply used because then it could be
implemented as a simple array. With the "shortstring" type, accessing the
count by index thus always required/s a type conversion between byte and
char (functions "ord" and "chr").

> <shortstring>[0] denotes the length byte, do you remember? An AnsiString

Anistrings were presented as "opake" types, where it was _not_ meant to be
possible to access the fields directly, specifically not the length value.
The _order_ and arrangement of the fields was not even officially specified
in the beginning.

> How many lines of string manipulating code did you write? I wrote

Don't know.

> countless. And often I switch to the C-notation (pchar(pointer
> (<thepascalstring>)) [index]) because of performance and convenience
> reasons.

Yes, that's exactly the opposite of my style. I prefer the "Pascal" way, as
introduced by UCSD Pascal and generalized and made public by former Borland.
I prefer _safe_ string handling, and it's been fast enough for my purposes
everytime in the past. I also prefer _static_ strings (and other data
types), because most of my programming pertains to small systems with
limited resources, which often cannot handle the large overhead dynamic
memory incurs.
(In addition, at least the "Pascal" string handling is inherently safe in
contrast to the C-style way. This means that programs using it are _not_
prone to buffer overflows or out-of-bounds accesses which are so well
regarded among the writers of malware programs. Similar safeguards have
only recently been added to newer C versions and variants, such as C#.)

-- 
(Weitergabe von Adressdaten, Telefonnummern u.ä. ohne Zustimmung
nicht gestattet, ebenso Zusendung von Werbung oder ähnlichem)
-----------------------------------------------------------
Mit freundlichen Grüßen, S. Schicktanz
-----------------------------------------------------------


------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
mseide-msegui-talk mailing list
mseide-msegui-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk

Reply via email to