Re: [fpc-pascal] Getting fast output

2008-07-23 Thread leledumbo


Jonas Maebe-2 wrote:
> 
> But that won't help you in this case, because settextbuf does not  
> change the flushing behaviour when writing to the screen. For that,  
> you have to follow Tomas' advice.
> 
Done, but I still demand it to be in System unit. That way, no additional
unit is needed. Does Delphi declare TextRec and FileRec anyway?
-- 
View this message in context: 
http://www.nabble.com/Getting-fast-output-tp18562328p18605192.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] freeing string equal to setting to empty string?

2008-07-23 Thread Jonas Maebe


On 23 Jul 2008, at 06:32, Marc Santhoff wrote:


I understand right that (as I have asked before) an empty (ansi)string
is equal to NIL.


True.


If this is correct, is setting a string to '' the same as setting the
string to NIL?


No.


So i can e.g. use exchagably:

{$H+}
var
 s: string;
begin
 s := 'something';

 { this ... }
 s := '';
 { ... works equally to that: }
 s := NIL;


No, because "s:=nil" doesn't compile. And pointer(s):=nil would create  
a memory leak.



And more: is the memory consumed by the string freed using one of the
two methods?


It is freed if you use s:='' (but keep in mind the earlier discussion  
about reference counted types: the memory may not be freed  
immediately, because there may still be hidden references lingering  
around for a while).



Jonas
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re[4]: [fpc-pascal] Ugly exception during compilation FPC 2.3.1 MacOS X 10.5 PowerPC

2008-07-23 Thread Roland Turcan
Hello Mattias,

Next backtrace:

Compiling ./unit/ResConf.pas
Assembling resconf
An unhandled exception occurred at $00148A20 :

Breakpoint 1, 0x00018100 in fpc_raiseexception ()
(gdb) bt
#0  0x00018100 in fpc_raiseexception ()
#1  0x0010dde4 in TOUTPUTFILTER__EXECUTE (THEPROCESS=0x2700a20, 
ACALLER=0x25ded00, ATOOL=0x27c3d90, this=0x27002a0)
#2  0x003b7bac in TEXTERNALTOOLLIST__RUN (EXTTOOL=0x27c3d90, MACROS=0x27aa800, 
THEOUTPUTFILTER=0x27002a0, COMPILEROPTIONS=0x27f4e90, this=0x25ded00) at 
exttooldialog.pas:370
#3  0x0017ebb8 in TBUILDMANAGER__ONRUNCOMPILERWITHOPTIONS (EXTTOOL=0x27c3d90, 
COMPOPTIONS=0x27f4e90, this=0x25cd860) at buildmanager.pas:1221
#4  0x0016e034 in TLAZPACKAGEGRAPH__COMPILEPACKAGE (APACKAGE=0x3148b80, 
FLAGS=Invalid C/C++ type code 10 in symbol table.
) at packagesystem.pas:2935
#5  0x0016d630 in TLAZPACKAGEGRAPH__COMPILEREQUIREDPACKAGES (APACKAGE=0x0, 
FIRSTDEPENDENCY=0x3156f60, GLOBALS=0x3107130, POLICIES=Invalid C/C++ type code 
10 in symbol table.
) at packagesystem.pas:2766
#6  0x401c in TLAZBUILDAPPLICATION__COMPILEAUTOINSTALLPACKAGES 
(this=0x2730090) at lazbuild.lpr:502
#7  0x3cd8 in TLAZBUILDAPPLICATION__BUILDLAZARUSIDE (this=0x2730090) at 
lazbuild.lpr:445
#8  0x686c in TLAZBUILDAPPLICATION__RUN (this=0x2730090) at lazbuild.lpr:978
#9  0x7fb8 in PASCALMAIN () at lazbuild.lpr:1167
#10 0x0002a9f0 in SYSTEM_FPC_SYSTEMMAIN$LONGINT$PPCHAR$PPCHAR ()
#11 0x276c in _start ()
#12 0x2470 in start ()
(gdb) c
Continuing.
EAccessViolation : Access violation
  $00148A20
  $001479C4
  $0014C8FC
  $0014B04C
  $001245B0
  $0014FE68
  $00150368
  $0013320C
  $0012B970
  $00109034
  $0011D3B4
  $0012AADC
  $0012ADF0
  $0012BB78
  $00Fatal: Compilation aborted
109034
  $0011D3B4
  $0012AADC

TExternalToolList.Run Exception: there was an error
ERROR: tool reported error

Program exited with code 02.
(gdb)


But I don't see any debug information from freepascal's executable.

This is really strange, because our package is compilable alone
without problem.

TRoland;

<<< 22.7.2008 15:27 - Mattias Gärtner "[EMAIL PROTECTED]" >>>
MG> Zitat von Roland Turcan <[EMAIL PROTECTED]>:

>> Hello all,
>>
>> Backtrace from lazbuild:
>>
>> An unhandled exception occurred at $00148A30 :
>>
>> Breakpoint 1, 0x00018090 in fpc_raiseexception ()
>> (gdb) bt
>> #0  0x00018090 in fpc_raiseexception ()
>> #1  0x001106d4 in CHECKFORURGENTMESSAGES (P=1, parentfp=0xbfffe0c0) at
>> outputfilter.pas:561
>> #2  0x0010e400 in TOUTPUTFILTER__READFPCOMPILERLINE (S=0x3129048,
>> this=0x27002a0)
>> #3  0x0010e0b8 in TOUTPUTFILTER__READLINE (S=0x3129048, DONTFILTERLINE=false,
>> this=0x27002a0) at outputfilter.pas:418
>> #4  0x0010dbcc in TOUTPUTFILTER__EXECUTE (THEPROCESS=0x2700a20,
>> ACALLER=0x25ded00, ATOOL=0x27c3ac0, this=0x27002a0)
>> #5  0x003b7c1c in TEXTERNALTOOLLIST__RUN (EXTTOOL=0x27c3ac0,
>> MACROS=0x27aa200, THEOUTPUTFILTER=0x27002a0, COMPILEROPTIONS=0x27f4e90,
>> this=0x25ded00) at exttooldialog.pas:370
>>[...]

MG> This exception is normal and caught in ide/exttooldialog.pas 387.
MG> Please continue and see what comes next:

MG> gdb ./lazarus.app/Contents/MacOS/lazarus
MG> break FPC_RAISEEXCEPTION
MG> r
MG> bt
MG> c
MG> bt
MG> c
MG> bt


MG> Mattias

MG> ___
MG> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
MG> http://lists.freepascal.org/mailman/listinfo/fpc-pascal




-- 
Best regards, TRoland
http://www.rotursoft.sk
http://exekutor.rotursoft.sk

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] how to catch fpopen() output

2008-07-23 Thread Graeme Geldenhuys
Hi,

I have a function called fpgOpenURL(...) which contains the following 

if fpsystem('which xdg-open') = 0 then
  Helper := 'xdg-open'
else if fpsystem('which firefox') = 0 then
  Helper := 'firefox';
else if fpsystem('which konqueror') = 0 then
  Helper := 'konqueror';
else if fpsystem('which opera') = 0 then
  Helper := 'opera';
else if fpsystem('which mozilla') = 0 then
   Helper := 'mozilla';

It tries to dected the preferred or installed web browser. If Helper
<> '' at the end, I know I found a web browser.  But how do I catch
the output of fpopen('which xxx') so that I can set the full path of
the application in  the 'Helper' variable.

eg:
   instead of using 'xdg-open'  I would prefer to set the full path
returned by 'which xdg-open' which is '/usr/bin/xdg-open'


Regards,
 - Graeme -


___
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


[fpc-pascal] Re: how to catch fpopen() output

2008-07-23 Thread Graeme Geldenhuys
Sorry, I meant catching fpSystem() output...



On Wed, Jul 23, 2008 at 2:40 PM, Graeme Geldenhuys
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have a function called fpgOpenURL(...) which contains the following 
>
>if fpsystem('which xdg-open') = 0 then
>  Helper := 'xdg-open'
>else if fpsystem('which firefox') = 0 then
>  Helper := 'firefox';
>else if fpsystem('which konqueror') = 0 then
>  Helper := 'konqueror';
>else if fpsystem('which opera') = 0 then
>  Helper := 'opera';
>else if fpsystem('which mozilla') = 0 then
>   Helper := 'mozilla';
>
> It tries to dected the preferred or installed web browser. If Helper
> <> '' at the end, I know I found a web browser.  But how do I catch
> the output of fpopen('which xxx') so that I can set the full path of
> the application in  the 'Helper' variable.
>
> eg:
>   instead of using 'xdg-open'  I would prefer to set the full path
> returned by 'which xdg-open' which is '/usr/bin/xdg-open'




Regards,
 - Graeme -


___
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Re: how to catch fpopen() output

2008-07-23 Thread ik
You should use pipes rather then fpSystem for that.

Ido

On Wed, Jul 23, 2008 at 3:44 PM, Graeme Geldenhuys
<[EMAIL PROTECTED]> wrote:
> Sorry, I meant catching fpSystem() output...
>
>
>
> On Wed, Jul 23, 2008 at 2:40 PM, Graeme Geldenhuys
> <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> I have a function called fpgOpenURL(...) which contains the following 
>>
>>if fpsystem('which xdg-open') = 0 then
>>  Helper := 'xdg-open'
>>else if fpsystem('which firefox') = 0 then
>>  Helper := 'firefox';
>>else if fpsystem('which konqueror') = 0 then
>>  Helper := 'konqueror';
>>else if fpsystem('which opera') = 0 then
>>  Helper := 'opera';
>>else if fpsystem('which mozilla') = 0 then
>>   Helper := 'mozilla';
>>
>> It tries to dected the preferred or installed web browser. If Helper
>> <> '' at the end, I know I found a web browser.  But how do I catch
>> the output of fpopen('which xxx') so that I can set the full path of
>> the application in  the 'Helper' variable.
>>
>> eg:
>>   instead of using 'xdg-open'  I would prefer to set the full path
>> returned by 'which xdg-open' which is '/usr/bin/xdg-open'
>
>
>
>
> Regards,
>  - Graeme -
>
>
> ___
> fpGUI - a cross-platform Free Pascal GUI toolkit
> http://opensoft.homeip.net/fpgui/
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>



-- 
http://ik.homelinux.org/
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: Re[4]: [fpc-pascal] Ugly exception during compilation FPC 2.3.1 MacOS X 10.5 PowerPC

2008-07-23 Thread Mattias Gärtner
Zitat von Roland Turcan <[EMAIL PROTECTED]>:

> Hello Mattias,
>
> Next backtrace:
>
> Compiling ./unit/ResConf.pas
> Assembling resconf
> An unhandled exception occurred at $00148A20 :
>
> Breakpoint 1, 0x00018100 in fpc_raiseexception ()
> (gdb) bt
> #0  0x00018100 in fpc_raiseexception ()
> #1  0x0010dde4 in TOUTPUTFILTER__EXECUTE (THEPROCESS=0x2700a20,
> ACALLER=0x25ded00, ATOOL=0x27c3d90, this=0x27002a0)

no line number. :(

> #2  0x003b7bac in TEXTERNALTOOLLIST__RUN (EXTTOOL=0x27c3d90,
> MACROS=0x27aa800, THEOUTPUTFILTER=0x27002a0, COMPILEROPTIONS=0x27f4e90,
> this=0x25ded00) at exttooldialog.pas:370
> #3  0x0017ebb8 in TBUILDMANAGER__ONRUNCOMPILERWITHOPTIONS (EXTTOOL=0x27c3d90,
> COMPOPTIONS=0x27f4e90, this=0x25cd860) at buildmanager.pas:1221
>[...]
> (gdb) c
> Continuing.
> EAccessViolation : Access violation
>[...]
> Fatal: Compilation aborted
>
> 109034
>   $0011D3B4
>   $0012AADC
>
> TExternalToolList.Run Exception: there was an error
> ERROR: tool reported error

This line should only appear, if the Exception is an EOutputFilterError, not on
EAccessViolation. Strange.
I will do some tests tonight on a Mac.


> Program exited with code 02.
> (gdb)
>
>
> But I don't see any debug information from freepascal's executable.
>
> This is really strange, because our package is compilable alone
> without problem.

Indeed.

Mattias

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: Re[4]: [fpc-pascal] Ugly exception during compilation FPC 2.3.1 MacOS X 10.5 PowerPC

2008-07-23 Thread Mattias Gärtner
Zitat von Roland Turcan <[EMAIL PROTECTED]>:

> Hello Mattias,
>
> Next backtrace:
>
> Compiling ./unit/ResConf.pas
> Assembling resconf
> An unhandled exception occurred at $00148A20 :
>
> Breakpoint 1, 0x00018100 in fpc_raiseexception ()
> (gdb) bt
> #0  0x00018100 in fpc_raiseexception ()
> #1  0x0010dde4 in TOUTPUTFILTER__EXECUTE (THEPROCESS=0x2700a20,
> ACALLER=0x25ded00, ATOOL=0x27c3d90, this=0x27002a0)
> #2  0x003b7bac in TEXTERNALTOOLLIST__RUN (EXTTOOL=0x27c3d90,
> MACROS=0x27aa800, THEOUTPUTFILTER=0x27002a0, COMPILEROPTIONS=0x27f4e90,
> this=0x25ded00) at exttooldialog.pas:370

I think the AV happens somewhere in the finally part of ide/outputfilter.pas
375.
I added some verbosity in rev 15849.
Please update lazarus svn and compile IDE and lazbuild clean with
-dVerboseOFExecute.
Then try again.

Can you reproduce the bug in a smaller package and send me the example?

Mattias

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] freeing string equal to setting to empty string?

2008-07-23 Thread Marc Santhoff
Am Mittwoch, den 23.07.2008, 08:28 +0100 schrieb Jonas Maebe:
> On 23 Jul 2008, at 06:32, Marc Santhoff wrote:
> 
> > I understand right that (as I have asked before) an empty (ansi)string
> > is equal to NIL.
> 
> True.
> 
> > If this is correct, is setting a string to '' the same as setting the
> > string to NIL?
> 
> No.
> 
> > So i can e.g. use exchagably:
> >
> > {$H+}
> > var
> >  s: string;
> > begin
> >  s := 'something';
> >
> >  { this ... }
> >  s := '';
> >  { ... works equally to that: }
> >  s := NIL;
> 
> No, because "s:=nil" doesn't compile.

Mumble ...

>  And pointer(s):=nil would create a memory leak.

That's the important part, I'm dealing with cleanly freeing strings when
destroying objects.

> > And more: is the memory consumed by the string freed using one of the
> > two methods?
> 
> It is freed if you use s:='' 

This is the way to do it, OK.

> (but keep in mind the earlier discussion  
> about reference counted types: the memory may not be freed  
> immediately, because there may still be hidden references lingering  
> around for a while).

I will. 

Many thanks,
Marc


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] how to catch fpopen() output

2008-07-23 Thread Marc Santhoff
Am Mittwoch, den 23.07.2008, 14:40 +0200 schrieb Graeme Geldenhuys:
> Hi,
> 
> I have a function called fpgOpenURL(...) which contains the following 
> 
> if fpsystem('which xdg-open') = 0 then
>   Helper := 'xdg-open'
> else if fpsystem('which firefox') = 0 then
>   Helper := 'firefox';
> else if fpsystem('which konqueror') = 0 then
>   Helper := 'konqueror';
> else if fpsystem('which opera') = 0 then
>   Helper := 'opera';
> else if fpsystem('which mozilla') = 0 then
>Helper := 'mozilla';
> 
> It tries to dected the preferred or installed web browser. If Helper
> <> '' at the end, I know I found a web browser.  But how do I catch
> the output of fpopen('which xxx') so that I can set the full path of
> the application in  the 'Helper' variable.
> 
> eg:
>instead of using 'xdg-open'  I would prefer to set the full path
> returned by 'which xdg-open' which is '/usr/bin/xdg-open'

I haven't done it myself, but I'm somewhat sure the standard answer for
this case is:

Use TProcess. There is a wiki page about it.

;)
Marc


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] freeing string equal to setting to empty string?

2008-07-23 Thread Luca Olivetti
El Wed, 23 Jul 2008 17:15:13 +0200
Marc Santhoff <[EMAIL PROTECTED]> escribió:

> That's the important part, I'm dealing with cleanly freeing strings
> when destroying objects.

I may be wrong but I think you don't need to do anything, when you free
a class the memory used by string fields is automagically freed
(either that or heaptrc is lying[*] when it says my programs aren't
leaking memory)

[*]though I know of at least a nasty leak with gtk2 under lazarus that
heaptrc didn't trace.

Bye
-- 
Luca
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] freeing string equal to setting to empty string?

2008-07-23 Thread Mattias Gaertner
On Wed, 23 Jul 2008 19:21:00 +0200
Luca Olivetti <[EMAIL PROTECTED]> wrote:

> El Wed, 23 Jul 2008 17:15:13 +0200
> Marc Santhoff <[EMAIL PROTECTED]> escribió:
> 
> > That's the important part, I'm dealing with cleanly freeing strings
> > when destroying objects.
> 
> I may be wrong but I think you don't need to do anything, when you
> free a class the memory used by string fields is automagically freed
> (either that or heaptrc is lying[*] when it says my programs aren't
> leaking memory)
> 
> [*]though I know of at least a nasty leak with gtk2 under lazarus that
> heaptrc didn't trace.

Which one?

Mattias
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] freeing string equal to setting to empty string?

2008-07-23 Thread Joao Morais

Luca Olivetti wrote:

El Wed, 23 Jul 2008 17:15:13 +0200
Marc Santhoff <[EMAIL PROTECTED]> escribió:


That's the important part, I'm dealing with cleanly freeing strings
when destroying objects.


I may be wrong but I think you don't need to do anything, when you free
a class the memory used by string fields is automagically freed
(either that or heaptrc is lying[*] when it says my programs aren't
leaking memory)


Yup. Ansi strings, refcounted interfaces and dyn arrays are 
automagically freed when declared as class members and you destroy the 
instance.


Joao Morais
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] freeing string equal to setting to empty string?

2008-07-23 Thread Luca Olivetti

En/na Mattias Gaertner ha escrit:


[*]though I know of at least a nasty leak with gtk2 under lazarus that
heaptrc didn't trace.


Which one?


http://bugs.freepascal.org/view.php?id=9259
(I just noticed you fixed it, but heaptrc didn't report anything when I 
first discovered it).


Bye
--
Luca

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] freeing string equal to setting to empty string?

2008-07-23 Thread Mattias Gaertner
On Wed, 23 Jul 2008 22:54:08 +0200
Luca Olivetti <[EMAIL PROTECTED]> wrote:

> En/na Mattias Gaertner ha escrit:
> 
> >> [*]though I know of at least a nasty leak with gtk2 under lazarus
> >> that heaptrc didn't trace.
> > 
> > Which one?
> 
> http://bugs.freepascal.org/view.php?id=9259
> (I just noticed you fixed it, but heaptrc didn't report anything when
> I first discovered it).

Heaptrc only checks the FPC heap. But in this case it was gtk memory. So
you need something like valgrind.

Mattias
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] how to catch fpopen() output

2008-07-23 Thread Anthony Henry

Could also use popen.


Sent from my iPhone

On Jul 23, 2008, at 11:11, Marc Santhoff <[EMAIL PROTECTED]> wrote:


Am Mittwoch, den 23.07.2008, 14:40 +0200 schrieb Graeme Geldenhuys:

Hi,

I have a function called fpgOpenURL(...) which contains the  
following 


   if fpsystem('which xdg-open') = 0 then
 Helper := 'xdg-open'
   else if fpsystem('which firefox') = 0 then
 Helper := 'firefox';
   else if fpsystem('which konqueror') = 0 then
 Helper := 'konqueror';
   else if fpsystem('which opera') = 0 then
 Helper := 'opera';
   else if fpsystem('which mozilla') = 0 then
  Helper := 'mozilla';

It tries to dected the preferred or installed web browser. If Helper
<> '' at the end, I know I found a web browser.  But how do I catch
the output of fpopen('which xxx') so that I can set the full path of
the application in  the 'Helper' variable.

eg:
  instead of using 'xdg-open'  I would prefer to set the full path
returned by 'which xdg-open' which is '/usr/bin/xdg-open'


I haven't done it myself, but I'm somewhat sure the standard answer  
for

this case is:

Use TProcess. There is a wiki page about it.

;)
Marc


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] freeing string equal to setting to empty string?

2008-07-23 Thread Marc Santhoff
Am Mittwoch, den 23.07.2008, 17:10 -0300 schrieb Joao Morais:
> Luca Olivetti wrote:
> > El Wed, 23 Jul 2008 17:15:13 +0200
> > Marc Santhoff <[EMAIL PROTECTED]> escribió:
> > 
> >> That's the important part, I'm dealing with cleanly freeing strings
> >> when destroying objects.
> > 
> > I may be wrong but I think you don't need to do anything, when you free
> > a class the memory used by string fields is automagically freed
> > (either that or heaptrc is lying[*] when it says my programs aren't
> > leaking memory)
> 
> Yup. Ansi strings, refcounted interfaces and dyn arrays are 
> automagically freed when declared as class members and you destroy the 
> instance.

That's interesting and nice. Can I assume the same is valid for dyn
arrays in a procedure or function context?

Normal vars do "behave" that way ...

program x;

procedure a;
var
  s: array of string;
begin
  SetLength(s, count);
  s[0] := 'a string';

  ... do something ...

end; { no freeing of the array strings needed? }


Marc

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] freeing string equal to setting to empty string?

2008-07-23 Thread Marc Santhoff
Am Mittwoch, den 23.07.2008, 19:21 +0200 schrieb Luca Olivetti:
> El Wed, 23 Jul 2008 17:15:13 +0200
> Marc Santhoff <[EMAIL PROTECTED]> escribió:
> 
> > That's the important part, I'm dealing with cleanly freeing strings
> > when destroying objects.
> 
> I may be wrong but I think you don't need to do anything, when you free
> a class the memory used by string fields is automagically freed
> (either that or heaptrc is lying[*] when it says my programs aren't
> leaking memory)

So as a rule of thumb strings can be used like any other non-object and
non-heap variable, as long as they are declared in the context of a
class.

If other objects or vars are holding pointers, ref counting prevents
freeing strings still needed.

Marc


___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] freeing string equal to setting to empty string?

2008-07-23 Thread David Emerson
On Wednesday 23 July 2008 7:46 pm, Marc Santhoff wrote:
> That's interesting and nice. Can I assume the same is valid for dyn
> arrays in a procedure or function context?

The short answer is yes.

There was recently (about a month ago) a discussion about some of these 
very issues, from 21 to 29 June. I'd encourage you to read it.

(Unfortunately I erroneously made the subject line "memory management 
with open arrays and classes"; and I replied to another thread instead 
of starting a new thread, so the messages don't appear in a nice little 
self-contained thread. doh!)

http://www.mail-archive.com/fpc-pascal@lists.freepascal.org/msg12918.html

...and three messages following; make sure you read the one by Jonas, as 
the first reply contains some misinformation.

~David.


> 
> Normal vars do "behave" that way ...
> 
> program x;
> 
> procedure a;
> var
>   s: array of string;
> begin
>   SetLength(s, count);
>   s[0] := 'a string';
> 
>   ... do something ...
> 
> end; { no freeing of the array strings needed? }
Indeed not. Even if s was an array of ansistrings, they would still be 
cleaned up automatically when the var goes out of scope.
> 
> 
> Marc

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal