Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2012-02

TBytes

37 messages · 6 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Martin Schreiber

Hi,
I read that we should use TBytes instead of AnsiString in order to implement combined binary/character buffers with automatic memory management. With AnsiString we used setlength() in order to allocate not initialized memory.
TBytes is defined as
"

    TBytes = array of Byte;

"
where setlength() fills the buffer with zeros. What should we use instead?

Thanks, Martin

Reply by email

Martin Schreiber
to Michael Schnell: Why ? To me ("Ansi"-) strings seem a lot more convenient in many cases (e.g. when…
Michael Schnell wrote 7 lines
On 02/28/2012 05:04 AM, Martin Schreiber wrote: > I read that we should use TBytes instead of AnsiString in order to > implement combined binary/character buffers with automatic memory > management. Why ?

Because of Delphi compatibility and code cleanness.

To me ("Ansi"-) strings seem a lot more convenient in many cases (e.g. when implementing a kind of protocol on a Byte Stream.

Me too. :-)
Often we need to combine buffer data from binary pieces and character data/strings.

Martin

Reply by email

Martin Schreiber
to Michael Schnell: I see: The "Unicode Threat" that makes "String" a moving target, forcing the poor…

This has been sent to the wrong address, sorry Michael.

Michael Schnell wrote 11 lines
> Often we need to combine buffer data from binary pieces and character > data/strings. > Obviously. So why not define decent types like "ByteString", "WordString", "DWordString", (maybe CharString, PointerString or whatever, too) allowing for the legacy string operations in an appropriately overloaded way ?

Or why not let it be as it is in FPC 2.6 and use UnicodeString for visible GUI purpose?

Martin

Reply by email

Martin Schreiber
to Sven Barth: For strings SetLength also fills the string with zeros as the following example shows:…
Sven Barth wrote 36 lines
For strings SetLength also fills the string with zeros as the following example shows: === example begin === program setlengthtest; var barr: array of Byte; b: Byte; s: AnsiString; c: Char; begin SetLength(barr, 20); for b in barr do Write(b, ' '); Writeln; SetLength(s, 20); for c in s do Write(Ord(c), ' '); Writeln; end. === example end === === output begin === PS P:\tests\oneshots> .\setlengthtest.exe 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 === output end === So SetLength is the operation to use in each case.

This is probably because in your testcase the memory is still clean, try with -gh. Additionally this behavior would not be Delphi compatible: "
When you use SetLength, existing characters in the string are preserved, but the contents of any newly allocated space is undefined. "
http://docwiki.embarcadero.com/RADStudio/en/Declaring_and_Initializing_Strings

Martin

Reply by email

Michael Schnell
to Martin Schreiber: Because of Delphi compatibility and code cleanness. Me too. :-) Often we need to combine…
Martin Schreiber wrote
Because of Delphi compatibility and code cleanness.

I see: The "Unicode Threat" that makes "String" a moving target, forcing the poor "String" type to be "visible Text" i.e. holding a (somehow) known encoding of its binary content.

Of course I do see both aspects: GUI programmers will hope that "strings" are just printable and thus the name of the "somehow encoded" type should stay "String", while technically, a String is just a decently managed sequence of "something".

Thus to me it's clear that a decent compiler should provide both: one or more types for appropriately encoded text and one or more types for sequences of binary objects. that both should be easily usable and provide fast operation as similar as possible to the legacy String handling.

Often we need to combine buffer data from binary pieces and character data/strings.

Obviously.

So why not define decent types like "ByteString", "WordString", "DWordString", (maybe CharString, PointerString or whatever, too) allowing for the legacy string operations in an appropriately overloaded way ?

-Michael

Reply by email

Sven Barth
to Martin Schreiber: I read that we should use TBytes instead of AnsiString in order to implement combined…
Martin Schreiber wrote 10 lines
Hi, I read that we should use TBytes instead of AnsiString in order to implement combined binary/character buffers with automatic memory management. With AnsiString we used setlength() in order to allocate not initialized memory. TBytes is defined as " TBytes = array of Byte; " where setlength() fills the buffer with zeros. What should we use instead?

For strings SetLength also fills the string with zeros as the following example shows:

=== example begin ===

program setlengthtest;
var
   barr: array of Byte;
   b: Byte;
   s: AnsiString;
   c: Char;
begin
   SetLength(barr, 20);
   for b in barr do
     Write(b, ' ');
   Writeln;
   SetLength(s, 20);
   for c in s do
     Write(Ord(c), ' ');
   Writeln;
end.

=== example end ===

=== output begin ===

PS P:\tests\oneshots> .\setlengthtest.exe
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

=== output end ===

So SetLength is the operation to use in each case.

Regards,
Sven

Reply by email

Martin Schreiber
to Sven Barth: I can't tell whether Delphi also uses FillChar (because I won't look at the source of…
Sven Barth wrote 13 lines
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.

Martin

Reply by email

Mattias Gaertner
to Sven Barth: For strings SetLength also fills the string with zeros as the following example shows:…
Show quoted text 42 lines
Am 28.02.2012 05:04, schrieb Martin Schreiber: > Hi, > I read that we should use TBytes instead of AnsiString in order to > implement combined binary/character buffers with automatic memory > management. With AnsiString we used setlength() in order to allocate not > initialized memory. > TBytes is defined as > " > TBytes = array of Byte; > " > where setlength() fills the buffer with zeros. What should we use instead? For strings SetLength also fills the string with zeros as the following example shows: === example begin === program setlengthtest; var barr: array of Byte; b: Byte; s: AnsiString; c: Char; begin SetLength(barr, 20); for b in barr do Write(b, ' '); Writeln; SetLength(s, 20); for c in s do Write(Ord(c), ' '); Writeln; end. === example end === === output begin === PS P:\tests\oneshots> .\setlengthtest.exe 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

That's because the OS gives you on first time a lot of zeroed mem. SetLength does not zero memory. Try this:

var
  i: Integer;
  s: string;
begin
  for i:=1 to 100000 do begin
    SetLength(s,1000000); // size does not matter for speed
    SetLength(s,1);
  end;
end.

Mattias

Reply by email

Sven Barth
to Martin Schreiber: This is probably because in your testcase the memory is still clean, try with -gh.…
Martin Schreiber wrote 44 lines
Am 28.02.2012 09:23, schrieb Sven Barth: > > For strings SetLength also fills the string with zeros as the following > example shows: > > === example begin === > > program setlengthtest; > > var > barr: array of Byte; > b: Byte; > s: AnsiString; > c: Char; > begin > SetLength(barr, 20); > for b in barr do > Write(b, ' '); > Writeln; > SetLength(s, 20); > for c in s do > Write(Ord(c), ' '); > Writeln; > end. > > === example end === > > === output begin === > > PS P:\tests\oneshots> .\setlengthtest.exe > 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > > === output end === > > So SetLength is the operation to use in each case. > This is probably because in your testcase the memory is still clean, try with -gh. Additionally this behavior would not be Delphi compatible: " When you use SetLength, existing characters in the string are preserved, but the contents of any newly allocated space is undefined. " http://docwiki.embarcadero.com/RADStudio/en/Declaring_and_Initializing_Strings

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.

Regards,
Sven

Reply by email

Martin Schreiber
to Marco van de Voort: In our previous episode, Martin Schreiber said: If you care, you can do manual…
Marco van de Voort wrote 12 lines
In our previous episode, Martin Schreiber said: > I read that we should use TBytes instead of AnsiString in order to > implement combined binary/character buffers with automatic memory > management. With AnsiString we used setlength() in order to allocate not > initialized memory. > TBytes is defined as > " > TBytes = array of Byte; > " > where setlength() fills the buffer with zeros. What should we use instead? If you care, you can do manual management.

Yup, MSEgui has allocuninitedarray() for the purpose. I don't think it is more "clean" or "secure" than the old ansistring method because it depends on compiler internals.

Or pool arrays of byte. (I do this in my Delphi app, where I have a nice generic pool class).

I like handy tools. Using FPC 2.6 AnsiString as buffer is handy.

But I don't think TBookmark is very speed-sensitive.

We don't talk about TBookmark only here. AFAIK all "string as databuffer" is prohibited in future FPC.

Martin

Reply by email

Sven Barth
to Michael Schnell: Ooops. Why are my contributions different from others ? I am just using Thunderbird and…
Michael Schnell wrote 8 lines
On 02/28/2012 09:34 AM, Sven Barth wrote: > > So I'm not the only one who often has this problem when answering to > one of Michael's mails Ooops. Why are my contributions different from others ? I am just using Thunderbird and do "answer to all" when replying to the list (as the list daemons often provide the list as a "cc" rather than a "from"

Maybe you should do an "answer to list" yourself? At least the FPC and Lazarus list daemons seem to be configured properly...

Regards,
Sven

Reply by email

Sven Barth
to Mattias Gaertner: On Tue, 28 Feb 2012 09:23:34 +0100 That's because the OS gives you on first time a lot of…
Mattias Gaertner wrote 58 lines
On Tue, 28 Feb 2012 09:23:34 +0100 Sven Barth wrote: > Am 28.02.2012 05:04, schrieb Martin Schreiber: >> Hi, >> I read that we should use TBytes instead of AnsiString in order to >> implement combined binary/character buffers with automatic memory >> management. With AnsiString we used setlength() in order to allocate not >> initialized memory. >> TBytes is defined as >> " >> TBytes = array of Byte; >> " >> where setlength() fills the buffer with zeros. What should we use instead? > > For strings SetLength also fills the string with zeros as the following > example shows: > > === example begin === > > program setlengthtest; > > var > barr: array of Byte; > b: Byte; > s: AnsiString; > c: Char; > begin > SetLength(barr, 20); > for b in barr do > Write(b, ' '); > Writeln; > SetLength(s, 20); > for c in s do > Write(Ord(c), ' '); > Writeln; > end. > > === example end === > > === output begin === > > PS P:\tests\oneshots> .\setlengthtest.exe > 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 > 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 That's because the OS gives you on first time a lot of zeroed mem. SetLength does not zero memory. Try this: var i: Integer; s: string; begin for i:=1 to 100000 do begin SetLength(s,1000000); // size does not matter for speed SetLength(s,1); end; end.

In the end I preferred looking at the source of SetLength as written to Martin already ;)

Regards,
Sven

Reply by email

Sven Barth
to Martin Schreiber: Same in Delphi? Martin
Martin Schreiber wrote 8 lines
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.

Regards,
Sven

Reply by email

Marco van de Voort
to Martin Schreiber: I read that we should use TBytes instead of AnsiString in order to implement combined…

In our previous episode, Martin Schreiber said:

Show quoted text 9 lines
I read that we should use TBytes instead of AnsiString in order to implement combined binary/character buffers with automatic memory management. With AnsiString we used setlength() in order to allocate not initialized memory. TBytes is defined as " TBytes = array of Byte; " where setlength() fills the buffer with zeros. What should we use instead?

If you care, you can do manual management. Or pool arrays of byte. (I do this in my Delphi app, where I have a nice generic pool class).

But I don't think TBookmark is very speed-sensitive.

Reply by email

Sven Barth
to Michael Schnell
Michael Schnell wrote 8 lines
On 02/28/2012 09:52 AM, Sven Barth wrote: > > Maybe you should do an "answer to list" yourself? At least the FPC and > Lazarus list daemons seem to be configured properly... > So you think the additional mail to the original poster is not appropriate. If so I'll happily do "answer list"

You should at least try.

Let's make a test: Answer to this mail once using "answer all" and once "answer list". Then I will answer to you using "answer list" and we'll see where the answers go.

Regards,
Sven

Reply by email

Michael Schnell
to Sven Barth
Sven Barth wrote
Let's make a test: Answer to this mail once using "answer all" and once "answer list". Then I will answer to you using "answer list" and we'll see where the answers go.

This is the "reply all" test message for Sven.

Those who are not concerned: please ignore.

-Michael

Reply by email

Michael Schnell
to Sven Barth: You should at least try. Let's make a test: Answer to this mail once using "answer all"…
Sven Barth wrote
Let's make a test: Answer to this mail once using "answer all" and once "answer list". Then I will answer to you using "answer list" and we'll see where the answers go.

This is the "reply to sender" test message for Sven. (_Here_ in fact it goes to the list. There are many other mailing lists that are not usable with "reply to sender". )

Those who are not concerned: please ignore.

-Michael

Reply by email

Michael Schnell
to Sven Barth: You should at least try. Let's make a test: Answer to this mail once using "answer all"…
Sven Barth wrote
Let's make a test: Answer to this mail once using "answer all" and once "answer list". Then I will answer to you using "answer list" and we'll see where the answers go.

This is the "reply to list" test message for Sven. (_Here_ this obviously word as desired. Not sure about other mailing lists.) Lets see if Thunderbird can be configured to show a "reply to List" Button.

Those who are not concerned: please ignore.

-Michael

Reply by email

Sven Barth
to Martin Schreiber: So using TBytes instead of FPC 2.6 AnsiString as buffer has a performance penalty. It has…
Martin Schreiber wrote 21 lines
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

Reply by email

Sven Barth
to Michael Schnell: This is the "reply to sender" test message for Sven. (_Here_ in fact it goes to the list.…
Michael Schnell wrote 16 lines
On 02/28/2012 10:43 AM, Sven Barth wrote: > Let's make a test: Answer to this mail once using "answer all" and > once "answer list". Then I will answer to you using "answer list" and > we'll see where the answers go. This is the "reply to sender" test message for Sven. (_Here_ in fact it goes to the list. There are many other mailing lists that are not usable with "reply to sender". ) Those who are not concerned: please ignore. -Michael _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Test answer with "reply to list" ("to" is indeed the list)

Regards,
Sven

Reply by email

Sven Barth
to Sven Barth
Sven Barth wrote 22 lines
Am 28.02.2012 10:47, schrieb Michael Schnell: > On 02/28/2012 10:43 AM, Sven Barth wrote: >> Let's make a test: Answer to this mail once using "answer all" and >> once "answer list". Then I will answer to you using "answer list" and >> we'll see where the answers go. > This is the "reply to sender" test message for Sven. (_Here_ in fact it > goes to the list. There are many other mailing lists that are not > usable with "reply to sender". ) > > Those who are not concerned: please ignore. > > -Michael > > > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-devel Test answer with "reply to list" ("to" is indeed the list) Regards, Sven

So it seems that you should use "reply to sender" as this was the only mail that went to the list with "reply to list"... Now it would be interesting to know why this is the case ^^

Regards,
Sven

Reply by email

Michael Schnell
to Sven Barth: Test answer with "reply to list" ("to" is indeed the list) Sven
Sven Barth wrote 25 lines
Am 28.02.2012 10:47, schrieb Michael Schnell: > On 02/28/2012 10:43 AM, Sven Barth wrote: >> Let's make a test: Answer to this mail once using "answer all" and >> once "answer list". Then I will answer to you using "answer list" and >> we'll see where the answers go. > This is the "reply to sender" test message for Sven. (_Here_ in fact it > goes to the list. There are many other mailing lists that are not > usable with "reply to sender". ) > > Those who are not concerned: please ignore. > > -Michael > > > _______________________________________________ > fpc-devel maillist - > http://lists.freepascal.org/mailman/listinfo/fpc-devel Test answer with "reply to list" ("to" is indeed the list) Regards, Sven _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/mailman/listinfo/fpc-devel

This in fact came back through the list.
-Michael

Reply by email

Michael Schnell
to Sven Barth: So it seems that you should use "reply to sender" as this was the only mail that went to…
Sven Barth wrote
So it seems that you should use "reply to sender" as this was the only mail that went to the list with "reply to list"... Now it would be interesting to know why this is the case ^^

Seemingly the list daemons can be configured regarding what to use as from and what as cc. Seemingly this is complicated and/or a matter of taste, as the different list work differently.

I do know that with several lists "reply to sender" does not work.

In fact I am quite sure that I more than never by chance did "reply to sender" in this list and the mail only was delivered to the original sender. So it seems to depend on his mailer, as well.

-Michael

Reply by email

Martin Schreiber
to Marco van de Voort: In our previous episode, Martin Schreiber said: getmem/freemem ? IMHO it is an abuse. One…
Marco van de Voort wrote 9 lines
In our previous episode, Martin Schreiber said: >> If you care, you can do manual management. > > Yup, MSEgui has allocuninitedarray() for the purpose. I don't think it > is more "clean" or "secure" than the old ansistring method because it > depends on compiler internals. getmem/freemem ?

And the layout of the variable array record.

Show quoted text 10 lines
>> Or pool arrays of byte. (I do >> this in my Delphi app, where I have a nice generic pool class). >> > I like handy tools. Using FPC 2.6 AnsiString as buffer is handy. IMHO it is an abuse. One could discuss if internal usage is a big problem (I think that is still bad though, but if you switch typing string to explicit ansistring, there is no rush), but I think at least public programming interfaces should be free of such gotchas.

[...]

Then please implement such a handy character string compatible automatic memory managed buffer type.
And please don't wait until Delphi has made it or Delphi changed string handling completely again which seems to be possible according a thread with Allen Bauer in Embarcadero forum. And please implement it before AnsiStrings can't be used for the purpose anymore.

Thanks, Martin

Reply by email

Martin Schreiber
to Marco van de Voort: In our previous episode, Martin Schreiber said: If it IS 1-byte character data,…
Marco van de Voort wrote 14 lines
In our previous episode, Martin Schreiber said: >> think that is still bad though, but if you switch typing string to explicit >> ansistring, there is no rush), but I think at least public >> programming interfaces should be free of such gotchas. >> > [...] > > Then please implement such a handy character string compatible automatic > memory managed buffer type. If it IS 1-byte character data, ansistring is fairly ok. The whole discussion was about stuffing binary data in a character type. > This was about a case where it was not character data.

Exactly. An automatically memory managed buffer type where binary and character data can be combined in a convenient manner and optimal performance. As FPC 2.6 AnsiString is.

Martin

Reply by email

Marco van de Voort
to Martin Schreiber: Yup, MSEgui has allocuninitedarray() for the purpose. I don't think it is more "clean" or…

In our previous episode, Martin Schreiber said:

Show quoted text 5 lines
> If you care, you can do manual management. Yup, MSEgui has allocuninitedarray() for the purpose. I don't think it is more "clean" or "secure" than the old ansistring method because it depends on compiler internals.

getmem/freemem ?

> Or pool arrays of byte. (I do > this in my Delphi app, where I have a nice generic pool class). > I like handy tools. Using FPC 2.6 AnsiString as buffer is handy.

IMHO it is an abuse. One could discuss if internal usage is a big problem (I think that is still bad though, but if you switch typing string to explicit ansistring, there is no rush), but I think at least public programming interfaces should be free of such gotchas.

In cases where tbytes behaviour is prohibitive due to performance, one probably shouldn't be using automated types in the first place.

> But I don't think TBookmark is very speed-sensitive. We don't talk about TBookmark only here. AFAIK all "string as databuffer" is prohibited in future FPC.

In the early 1.9.x days, when I ported Delphi code to FPC, half of the difficult bugs were related to this kind of abusing internals, specially the relying on autoconversions (of pchar, arrays of char etc). But then, pchar based items were the only overindexable type in Delphi, and that was a must nack then. Nowadays, other types are overindexable too, or at least can be made too, so there is no reason to continue these practices.

Yes, if it is just one person with complete oversight doing it himself, one can easily get away with it, specially since changes like the D2009 unicode transition don't happen every day. But this kind of hidden assumptions is errorprone if you have multiple persons working on the code, specially if some don't know the ins and outs of the code 100%, and very long term increases the number of spots where maintenance must be done significantly.

There have been such cases (and heated discussions) in the past, e.g. when people abused shortstring, and code stopped working when code was switched to ansistring because characters were accessed that were not <=length(s). Nobody argues that ansistring "should be fixed" for that anymore, and in 5 years nobody will care about this either :-)

Reply by email

Marco van de Voort
to Martin Schreiber: And the layout of the variable array record. [...] Then please implement such a handy…

In our previous episode, Martin Schreiber said:

Show quoted text 8 lines
> think that is still bad though, but if you switch typing string to explicit > ansistring, there is no rush), but I think at least public > programming interfaces should be free of such gotchas. > [...] Then please implement such a handy character string compatible automatic memory managed buffer type.

If it IS 1-byte character data, ansistring is fairly ok. The whole discussion was about stuffing binary data in a character type.

Show quoted text 5 lines
This was about a case where it was not character data. And please don't wait until Delphi has made it or Delphi changed string handling completely again which seems to be possible according a thread with Allen Bauer in Embarcadero forum. And please implement it before AnsiStrings can't be used for the purpose anymore.

If you care about the repeated addition stuff, you should probably be check out tstringbuilder. It is said to performance better with string concatenation then ansistring. I never use it though, but that is partially also because currently I don't work much with character data.

Reply by email

Sven Barth
to Marco van de Voort: In our previous episode, Martin Schreiber said: If it IS 1-byte character data,…
Marco van de Voort wrote 10 lines
> This was about a case where it was not character data. > And please don't wait until Delphi has made it or Delphi changed string > handling completely again which seems to be possible according a thread > with Allen Bauer in Embarcadero forum. And please implement it before > AnsiStrings can't be used for the purpose anymore. If you care about the repeated addition stuff, you should probably be check out tstringbuilder. It is said to performance better with string concatenation then ansistring. I never use it though, but that is partially also because currently I don't work much with character data.

Do we already have a TStringBuilder?

Regards,
Sven

Reply by email

Marco van de Voort
to Sven Barth

In our previous episode, Sven Barth said:

Show quoted text 10 lines
>> handling completely again which seems to be possible according a thread >> with Allen Bauer in Embarcadero forum. And please implement it before >> AnsiStrings can't be used for the purpose anymore. > > If you care about the repeated addition stuff, you should probably be check > out tstringbuilder. It is said to performance better with string > concatenation then ansistring. I never use it though, but that is partially > also because currently I don't work much with character data. Do we already have a TStringBuilder?

I don't know. As said I don't use it :)

Reply by email

Sergei Gorelkin
to Marco van de Voort

28.02.2012 16:31, Marco van de Voort пишет:

Show quoted text 13 lines
In our previous episode, Sven Barth said: >>> handling completely again which seems to be possible according a thread >>> with Allen Bauer in Embarcadero forum. And please implement it before >>> AnsiStrings can't be used for the purpose anymore. >> >> If you care about the repeated addition stuff, you should probably be check >> out tstringbuilder. It is said to performance better with string >> concatenation then ansistring. I never use it though, but that is partially >> also because currently I don't work much with character data. > > Do we already have a TStringBuilder? I don't know. As said I don't use it :)

I use something like that in fcl-xml package, not in the form of a class but a record and a set of procedures (see xmlutils.pp: TWideStringBuf, BufAppend(), etc).

Regards,
Sergei

Reply by email

Sven Barth
to Marco van de Voort: In our previous episode, Sven Barth said: I don't know. As said I don't use it :)
Marco van de Voort wrote 13 lines
In our previous episode, Sven Barth said: >>> handling completely again which seems to be possible according a thread >>> with Allen Bauer in Embarcadero forum. And please implement it before >>> AnsiStrings can't be used for the purpose anymore. >> >> If you care about the repeated addition stuff, you should probably be check >> out tstringbuilder. It is said to performance better with string >> concatenation then ansistring. I never use it though, but that is partially >> also because currently I don't work much with character data. > > Do we already have a TStringBuilder? I don't know. As said I don't use it :)

The interface of TStringBuilder is documented rather well in the Embarcadero wiki (it's described as an equivalent implementation of the StringBuilder class of .NET). So I might give it a try once I've finished my last exam for this term on Thursday...

Regards,
Sven

Reply by email