Sign in Join

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

Mailing lists / fpc-devel / 2007-11

Widestring and reference counting

5 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Graeme Geldenhuys

Hi,

I was reading a article on Delphi's WideString support. It mentions that under Delphi, WideStrings are not reference counted, but under Kylix they are.
http://tobias.feedian.com/2007/05/24/whats-wrong-with-delphis-widestring/

Using the following example program and compiling with 'fpc -al wstest.pas' under Linux to see the assembler file (not that I can remember anything of how assembler works). Looking at the asm code I see a call to FPC_WIDESTR_INCR_REF which I assume confirms that WideStrings under Linux using FPC is also reference counted.

Is the same true under Windows? Does that mean FPC doesn't have the WideString issues Delphi has?

-------------------------------------
program wstest;
uses
  Classes, SysUtils;
procedure Log(AParam: WideString);
var
  lparam: WideString;
begin
  lParam := AParam;
end;
begin
  Log('This is a test');
end.
----------------------

<....snip....>
# [12] lParam := AParam;
leal -4(%ebp),%eax
call FPC_WIDESTR_INCR_REF
leal -8(%ebp),%eax
call FPC_WIDESTR_DECR_REF
movl -4(%ebp),%eax
movl %eax,-8(%ebp)
<...snip...>

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

peter green
to Graeme Geldenhuys
Show quoted text 10 lines
Using the following example program and compiling with 'fpc -al wstest.pas' under Linux to see the assembler file (not that I can remember anything of how assembler works). Looking at the asm code I see a call to FPC_WIDESTR_INCR_REF which I assume confirms that WideStrings under Linux using FPC is also reference counted. Is the same true under Windows? Does that mean FPC doesn't have the WideString issues Delphi has?

Widestrings under windows are not reference counted for OLE compatibility, on all other platforms they are reference counted.

Reply by email

Martin Schreiber
to Graeme Geldenhuys: I was reading a article on Delphi's WideString support. It mentions that under Delphi,…
Graeme Geldenhuys wrote 18 lines
Hi, I was reading a article on Delphi's WideString support. It mentions that under Delphi, WideStrings are not reference counted, but under Kylix they are. http://tobias.feedian.com/2007/05/24/whats-wrong-with-delphis-widestring/ Using the following example program and compiling with 'fpc -al wstest.pas' under Linux to see the assembler file (not that I can remember anything of how assembler works). Looking at the asm code I see a call to FPC_WIDESTR_INCR_REF which I assume confirms that WideStrings under Linux using FPC is also reference counted. Is the same true under Windows? Does that mean FPC doesn't have the WideString issues Delphi has?

Widestrings were reference counted on all platforms before FPC 2.2 . With version 2.2 FPC switched to the Delphi behaviour on Windows in order to achieve COM compatibility.
Cossplatform unicode applications like MSEide+MSEgui: http://sourceforge.net/projects/mseide-msegui
suffer from the performance loss due to the non reference counted widestrings on Windows. MSEide+MSEgui is completely done with widestrings. I suggest to introduce a new COM compatible OLE-string type and let widestrings be reference counted on all platforms. It seems that CodeGear plans to go a similar route: http://groups.google.ch/group/borland.public.delphi.non-technical/msg/7caeced42f1934a4?hl=en& The introduced string handling for the "Unicode VCL" is equivalent to the string handling in MSEgui BTW.

Martin

Reply by email