[fpc-devel] TBytes
Sven Barth
pascaldragon at googlemail.com
Tue Feb 28 10:50:47 CET 2012
Am 28.02.2012 09:28, schrieb Martin Schreiber:
> Am 28.02.2012 10:10, schrieb Sven Barth:
>> Am 28.02.2012 09:07, schrieb Martin Schreiber:
>>> Am 28.02.2012 09:46, schrieb Sven Barth:
>>>
>>>>
>>>> You are right, I checked the code of SetLength for arrays and strings
>>>> and only arrays use FillChar. Nevertheless there is no other operation
>>>> you can use for arrays.
>>>>
>>> Same in Delphi?
>>
>> I can't tell whether Delphi also uses FillChar (because I won't look at
>> the source of Delphi's RTL), but there is also no other operation.
>>
> So using TBytes instead of FPC 2.6 AnsiString as buffer has a
> performance penalty.
> It has a convenience penalty too because TBytes can not be concatenated
> by "+". Using operator overloading is maybe not Delphi compatible and
> probably has less performance than the optimized concat*() string
> compiler procs. There AFAIK also is no convenient way to concatenate
> TBytes with string constants and variables.
At least in FPC 2.7.1 a "+" on strings can(!) have a higher performance
impact as a custom overloaded operator for an array, because a code page
conversion might be done, but also if that would not be the case (e.g.
in FPC 2.6) the concat functions basically also boil down to the
following code (copied from my mail to Michael on Lazarus list regarding
"TByteString"):
=== code begin ===
SetLength(Result, Length(aLeft) + Length(aRight));
if Length(aLeft) > 0 then
Move(aLeft[0], Result[0], Length(aLeft) * SizeOf(Byte));
if Length(aRight) > 0 then
Move(aRight[0], Result[Length(aLeft)], Length(aRight) * SizeOf(Byte));
=== code end ===
It's true though that you can't concat arrays using "+" in Delphi,
because you can't globally overload operators...
Regards,
Sven
More information about the fpc-devel
mailing list