Hello, sorry, but i have a little question, and did not know whom to ask, i found no answer in faq's neither to Gnu C nor to Gnu-Pascal. I use Gnu-Pascal for scientific reasons, and have some trouble with it (but it's a very good program!). First: I use an Pc with Linux (2XPPro 200, 256 MB Memory) Kernel 2.0.33 (new) and gpc version 2.0(2.7.2.1) . But i saw this problem with other configurations and Versions. The Problem is if i want to use much memory e.g. for arrays the compiled program results in segmentation fault, while it runs with smaller arrays. ( I found this program in Gnu-C also with static arrays). Here is an attached test program, that runs with xsiz<1010 and not with xsiz > 1050. In my opinion it's not a problem of Linux, it's a problem of gnu-C, maybe any wrong configuration. Did you hear about a solution.
Sincerly Joerg Tomes
************************************************************ Joerg Tomes, Theoretische Festkoerperphysik, Uni-Tuebingen, Auf der Morgenstelle 14, D-72076 Tuebingen, Tel : 07071-29-78633 Fax : 07071-29-5604 email: joerg.tomes@uni-tuebingen.de ************************************************************
program benchmark; const xsiz=1010; ysiz=1000; var a,b:real; d:array[0..xsiz,0..ysiz] of real; i,j:integer; Begin a:=1.0; For j:=1 to xsiz do For i:=1 to ysiz do begin d[i,j]:=a; end; b:=0.0; For j:=1 to xsiz do For i:=1 to ysiz do begin b:=b+d[i,j]; end; writeln(b,': Array entries used'); end.
Hallo, Joerg! Hello, everybody!
According to Joerg Tomes:
The Problem is if i want to use much memory e.g. for arrays the compiled program results in segmentation fault, while it runs with smaller arrays.
IIRC, gpc-2.0 stores global variables of the main program not in the data segment (where they belong) but in the stack segment whose size is limited in Linux (and in other systems).
Solutions:
* Upgrade to a more recent (beta) version of GNU-Pascal. See http://home.pages.de/~GNU-Pascal/ressources.html and/or ftp://agnes.dida.physik.uni-essen.de/gnu-pascal/beta/.
* Move the global variables to a Unit instead of the main program.
* Use pointers to work around:
Type Matrix = array [ 0..xsiz, 0..ysiz ] of Real;
Var d: ^Matrix;
...
New ( d ); d^ [ 42, 42 ]:= 42; Dispose ( d );
( I found this program in Gnu-C also with static arrays). [...]
Really? If you mean something like
int main ( ) { double d [ xsiz + 1 ] [ ysiz + 1 ]; }
then the array is an automatic (local), not a static variable. Then of course it causes the same problem. The following should work:
int main ( ) { static double d [ xsiz + 1 ] [ ysiz + 1 ]; }
or
double d [ xsiz + 1 ] [ ysiz + 1 ];
int main ( ) { }
Hope this helps,
Peter -- Peter Gerwinski, Essen, Germany, free physicist and programmer Maintainer GNU Pascal - http://home.pages.de/~GNU-Pascal/ - 1 Oct 1997 PGP key fingerprint: AC 6C 94 45 BE 28 A4 96 0E CC E9 12 47 25 82 75 Fight the SPAM! - http://maps.vix.com/