Recent

Author Topic: Strange Memory problem in Lazarus!  (Read 5837 times)

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 331
  • Love my Wife, My Kids and Lazarus/Freepascal.
Strange Memory problem in Lazarus!
« on: April 01, 2012, 05:37:53 pm »
Hi Friends.
I have Linux Ubuntu amd64 and Lazarus 0.9.30.2.

In my Lazarus program,that I made I declared this as global:(This is a large statistic program that works fine in Delphi 4)

numbers:array[1..10000,1..20]of integer;
numberstxt:array[1..10000]of string;
datetxt:array[1..10000]of string;

odd:array[1..10000]of string;
even:array[1..10000]of string;
pr:array[1..10000]of string;

back:array[1..10000]of string;
row:array[1..10000]of string;
nr2:array[1..10000]of string;
best:array[1..10000]of string;
lowest:array[1..10000]of string;
t:array[1..10000]of string;
srt:array[1..10000]of string;
inrow:array[1..10000]of string;
ownsttxt:array[1..10000]of string;
worked:array[1..10000]of string;
rowinrow:array[1..10000]of string;
rowinrowtxt:array[1..10000]of string;
nrr1:array[1..10000]of string;
statistic1:array[1..10000]of string;
md:array[1..10000]of string;
filtxt:textfile;
antal:integer;

I pick up 6000 numbers and place then in my variable numbers(declared 10000,20) and in numberstxt(declared 10000).
antal is 6000 and store it in my textfile like this:

assignFile(filtxt,'vikingrader.dbs');
rewrite(filtxt);

writeln(filtxt,antal);
for a2:=1 to antal do begin
writeln(filtxt,numberstxt(.a2.));
writeln(filtxt,datetxt(.a2.));
end;
for a2:=1 to antal do begin
for b2:=1 to 20 do begin
writeln(filtxt,numbers(.a2,b2.));
end;
end;
closefile(filtxt);   

Here is the problem.

When I look in the textfile I see that the texfile can't store the whole 6000,20 numbers in the textfile when the declaration is 10000,20? and not loading it either!
Solution:
If I lower my declaration of variables from 10000,20 to 7000,20   , the file saves all 6000,20 numbers variable!

Is this a Memoryproblem in Linux,Lazarus ?    ::)

Best regards
Rob     

« Last Edit: April 01, 2012, 05:39:41 pm by robbanux »
Rob

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Strange Memory problem in Lazarus!
« Reply #1 on: April 01, 2012, 06:18:02 pm »
Your code works well here.
I declared 10000,20.
Output file contains:
6000
followed by 12000 empty lines
followed by 120000 zeros
(totally 132001 lines).

No idea where is problem. Maybe mode?
I use {$mode objfpc}
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 331
  • Love my Wife, My Kids and Lazarus/Freepascal.
Re: Strange Memory problem in Lazarus!
« Reply #2 on: April 01, 2012, 08:33:31 pm »
Hi Blaazen. Have You filled up the array numbers with 6000,20 rows and save it in a textfile and the try to load it again!

the textfile I can't see that all the 6000 rows is in the textfile but,when i declare my numbers array from 10000,20 to 7000,20 all 6000,20 numbers is saved and also it could be loaded in my project!

The anything to get this to work for me is to declare the numbers variable from 10000,20 to 7000,20?

Really strange way to solve the problem!

Also,I have in the nearest future have to declare numbers to 15000,20 to fit all the statististic I will need.

Best regards
Rob
Rob

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Strange Memory problem in Lazarus!
« Reply #3 on: April 01, 2012, 08:42:13 pm »
Can you paste here your code for loading data from textfile? It will help us to help you.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 331
  • Love my Wife, My Kids and Lazarus/Freepascal.
Re: Strange Memory problem in Lazarus!
« Reply #4 on: April 01, 2012, 09:31:03 pm »
//
   Here is the code to fill the array but Yoy also need the beginning code that I wrote before.
Note! the numberstxt array shall be exluded and not used but,the rest of the declared variables should be in the code for the project.

A listbox and a button needed on a form.

See if after You saving it to a textfile,that You can load the numbersarray into the listbox again.

procedure TForm1.Button1Click(Sender: TObject);
var
  a,b,c,d:integer;

  antal:integer;
  numbers:array[1..10000,1..20]of integer;

begin

 antal:=6000;
 c:=80;
 for a:=1 to antal do begin
 for b:=1 to 20 do begin
  numbers[a,b]:=random(c);
 end;
 end;

 listbox1.Clear;

 for d:=1 to antal do begin

 listbox1.items.add(IntToStr(numbers[d,1])+','+IntToStr(numbers[d,2])
 +','+IntToStr(numbers[d,3])+','+IntToStr(numbers[d,4])+','+IntToStr(numbers[d,5])
 +','+IntToStr(numbers[d,6])+','+IntToStr(numbers[d,7])+','+IntToStr(numbers[d,8])
 +','+IntToStr(numbers[d,9])+','+IntToStr(numbers[d,10])+','+IntToStr(numbers[d,11])
 +','+IntToStr(numbers[d,12])+','+IntToStr(numbers[d,13])+','+IntToStr(numbers[d,14])
 +','+IntToStr(numbers[d,15])+','+IntToStr(numbers[d,16])
 +','+IntToStr(numbers[d,17])+','+IntToStr(numbers[d,18])
 +','+IntToStr(numbers[d,19])+','+IntToStr(numbers[d,20])
 );

 end;


end;

regards
Rob
  //
                           
Rob

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12566
  • FPC developer.
Re: Strange Memory problem in Lazarus!
« Reply #5 on: April 01, 2012, 10:10:48 pm »
Make the variable global.

Local variables are allocated from the stack, which is typically limited to something in the magnitude of 1MB on Linux.

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Strange Memory problem in Lazarus!
« Reply #6 on: April 01, 2012, 10:39:22 pm »
Isn't default linux stack size 8MB ?
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12566
  • FPC developer.
Re: Strange Memory problem in Lazarus!
« Reply #7 on: April 01, 2012, 11:01:50 pm »
Isn't default linux stack size 8MB ?

I guess it changes every couple of years as avg memory progresses, and might depend on distro.

Robert W.B.

  • Sr. Member
  • ****
  • Posts: 331
  • Love my Wife, My Kids and Lazarus/Freepascal.
Re: Strange Memory problem in Lazarus!
« Reply #8 on: April 02, 2012, 01:13:05 am »
In my project the variables are global.
Just the one ex: i filled with random numbers are in the exampel is local.

I got the memory problem even if variables are global in Ubuntu amd64. double core,4gb ram

Isn't default linux stack size 8MB ? What is it for Windows 7,Local Global?

Regards
Rob
Rob

 

TinyPortal © 2005-2018