Re: [fpc-pascal] string memory management

2013-04-19 Thread Sven Barth
Am 19.04.2013 09:38, schrieb Xiangrong Fang: 2013/4/19 Michael Van Canneyt > 1. I don't know whether I have to MANUALLY free memory for these strings to prevent leak? Yes, if you work like this, you must do all that. You must free al

Re: [fpc-pascal] string memory management

2013-04-19 Thread Xiangrong Fang
2013/4/19 Michael Van Canneyt > > 1. I don't know whether I have to MANUALLY free memory for these strings to > >> prevent leak? >>> >> > Yes, if you work like this, you must do all that. You must free all > pointers in the list, and the strings they point to. > > But why not use TStringList ? It

Re: [fpc-pascal] string memory management

2013-04-19 Thread Sven Barth
Am 19.04.2013 06:36, schrieb Xiangrong Fang: Hi All, I'm studying how pascal manages strings. I wrote a simple test program: program stringtest; {$mode objfpc}{$H+} uses Classes, sysutils; function test: PString; var s : string; begin New(Result); Result^ := FloatToStr(Random); // s :=

Re: [fpc-pascal] string memory management

2013-04-19 Thread Michael Van Canneyt
On Fri, 19 Apr 2013, Flávio Etrusco wrote: On Fri, Apr 19, 2013 at 1:36 AM, Xiangrong Fang wrote: Hi All, I'm studying how pascal manages strings. I wrote a simple test program: program stringtest; {$mode objfpc}{$H+} uses Classes, sysutils; function test: PString; var s : string; begin

Re: [fpc-pascal] string memory management

2013-04-18 Thread Flávio Etrusco
On Fri, Apr 19, 2013 at 1:36 AM, Xiangrong Fang wrote: > Hi All, > > I'm studying how pascal manages strings. I wrote a simple test program: > > program stringtest; > {$mode objfpc}{$H+} > uses Classes, sysutils; > function test: PString; > var > s : string; > begin > New(Result); > Result^

[fpc-pascal] string memory management

2013-04-18 Thread Xiangrong Fang
Hi All, I'm studying how pascal manages strings. I wrote a simple test program: program stringtest; {$mode objfpc}{$H+} uses Classes, sysutils; function test: PString; var s : string; begin New(Result); Result^ := FloatToStr(Random); // s := FloatToStr(Random); // Result := @s; end; var