Hi all
After sucessfully installing GPC I tried the following (basically a loop around the stringutils test-program). However it seems to have a memoryleak, after a while (~14%MEM on my machine) it comes out with a segmentation fault (and with top you can see that the memory usage grows)... What am I doing wrong?
Best regards
Preben Bohn
program test1;
uses GPC, stringutils;
var tokens : PPStrings; line : string; lineNumber : integer; c : charset; begin c := ['¤']; lineNumber := 0; while lineNumber < 1000000 do begin line := 'string1¤string2¤string3¤string4¤string5¤string6'; inc(lineNumber); tokens := TokenizeString (line, c); if (linenumber mod 10) = 0 then begin writeln('Line number : ', lineNumber); writeln(tokens^[1]^ + ' ' + tokens^[2]^+ ' ' + tokens^[3]^+ ' ' + tokens^[4]^+ ' ' + tokens^[5]^+ ' ' + tokens^[6]^); end; DisposePPStrings (tokens); end; end.
=====
__________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com
=?iso-8859-1?q?Preben=20Mikael=20Bohn?= wrote:
After sucessfully installing GPC I tried the following (basically a loop around the stringutils test-program). However it seems to have a memoryleak, after a while (~14%MEM on my machine) it comes out with a segmentation fault (and with top you can see that the memory usage grows)...
The memory leak is not in the unit, but in GPC itself. It's a known problem with some string operations (especially concatenation) in a loop. (If you can read /proc/n/maps, you'll see that it's the stack, not the heap that grows.) Moving the thing out of the loop (syntactically, e.g. in a subroutine) is a work-around.
Frank
I don't know if I understand you the right way (I probably don't). I just tried to move tokenize+dispose into a subroutine (but still in the loop) like the following, but it still has a memory leak...
program test1;
uses GPC, stringutils;
function split( var inStr : string; var os1,os2,os3,os4,os5,os6 : string; var c : charset ) : integer; var tokens : PPStrings; begin tokens := TokenizeString (inStr, c); os1 := tokens^[1]^; os2 := tokens^[2]^; os3 := tokens^[3]^; os4 := tokens^[4]^; os5 := tokens^[5]^; os6 := tokens^[6]^; split := tokens^.count; DisposePPStrings (tokens); end;
var line,os1,os2,os3,os4,os5,os6 : string; lineNumber, count : integer; c : charset;
begin c := ['¤']; lineNumber := 0; while lineNumber < 1000000 do begin line := 'string1¤string2¤string3¤string4¤string5¤string6'; inc(lineNumber); count := split(line, os1,os2,os3,os4,os5,os6,c); if (linenumber mod 10) = 0 then begin writeln('Line number : ', lineNumber); writeln(os1+' '+os2+os3+os4+os5+os6); end; end; end.
Best regards
Preben Bohn
--- Frank Heckenbach frank@g-n-u.de wrote: > =?iso-8859-1?q?Preben=20Mikael=20Bohn?= wrote:
After sucessfully installing GPC I tried the following
(basically a
loop around the stringutils test-program). However it seems to
have
a memoryleak, after a while (~14%MEM on my machine) it comes
out
with a segmentation fault (and with top you can see that the
memory
usage grows)...
The memory leak is not in the unit, but in GPC itself. It's a known problem with some string operations (especially concatenation) in a loop. (If you can read /proc/n/maps, you'll see that it's the stack, not the heap that grows.) Moving the thing out of the loop (syntactically, e.g. in a subroutine) is a work-around.
Frank
-- Frank Heckenbach, frank@g-n-u.de, http://fjf.gnu.de/, 7977168E GPC To-Do list, latest features, fixed bugs: http://www.gnu-pascal.de/todo.html
=====
__________________________________________________ Do You Yahoo!? Everything you'll ever need on one web page from News and Sport to Email and Music Charts http://uk.my.yahoo.com