How much memory does my program need?
I got "Memory limit exceeded" with this program, however I can't
understand how can it demand more than about 30
var
n:integer;
a:array[1..3000] of longint; { 12 kb here }
i,j:integer;
procedure order(i,j:integer); { In this procedure maximum is 18 kb}
var {becuase recursion maximum depth here}
q:integer; {is 3000}
begin
{if i=j then
begin
write(a[i]);
exit;
end; }
for q:=i to j do if a[q]>a[j] then break;
if q<j then order(q,j-1);
if q>i then order(i,q-1);
write(a[j]);
if j<>n then write(' ');
end;
begin
readln(n);
for I:=1 to n do read(a[i]);
order(1,n);
end.
When I change a:array [1..3000] to a:array [1..1] It got MEMOY LIMITE 1159Kb
> I got "Memory limit exceeded" with this program, however I can't
> understand how can it demand more than about 30
>
> var
> n:integer;
> a:array[1..3000] of longint; { 12 kb here }
> i,j:integer;
>
> procedure order(i,j:integer); { In this procedure maximum is 18 kb}
> var {becuase recursion maximum depth here}
> q:integer; {is 3000}
> begin
> {if i=j then
> begin
> write(a[i]);
> exit;
> end; }
>
> for q:=i to j do if a[q]>a[j] then break;
>
> if q<j then order(q,j-1);
> if q>i then order(i,q-1);
> write(a[j]);
> if j<>n then write(' ');
>
> end;
>
>
> begin
> readln(n);
> for I:=1 to n do read(a[i]);
> order(1,n);
>
>
> end.
>
>
Re: When I change a:array [1..3000] to a:array [1..1] It got MEMOY LIMITE 1159Kb
So, what do you think is the reason?
> > I got "Memory limit exceeded" with this program, however I can't
> > understand how can it demand more than about 30
> >
> > var
> > n:integer;
> > a:array[1..3000] of longint; { 12 kb here }
> > i,j:integer;
> >
> > procedure order(i,j:integer); { In this procedure maximum is 18
kb}
> > var {becuase recursion maximum depth
here}
> > q:integer; {is 3000}
> > begin
> > {if i=j then
> > begin
> > write(a[i]);
> > exit;
> > end; }
> >
> > for q:=i to j do if a[q]>a[j] then break;
> >
> > if q<j then order(q,j-1);
> > if q>i then order(i,q-1);
> > write(a[j]);
> > if j<>n then write(' ');
> >
> > end;
> >
> >
> > begin
> > readln(n);
> > for I:=1 to n do read(a[i]);
> > order(1,n);
> >
> >
> > end.
> >
> >
I have such event to. I hed a:array [1..37] of boolean and got ML. I don't know whi.
> So, what do you think is the reason?
>
>
>
>
>
> > > I got "Memory limit exceeded" with this program, however I
can't
> > > understand how can it demand more than about 30
> > >
> > > var
> > > n:integer;
> > > a:array[1..3000] of longint; { 12 kb here }
> > > i,j:integer;
> > >
> > > procedure order(i,j:integer); { In this procedure maximum is 18
> kb}
> > > var {becuase recursion maximum depth
> here}
> > > q:integer; {is 3000}
> > > begin
> > > {if i=j then
> > > begin
> > > write(a[i]);
> > > exit;
> > > end; }
> > >
> > > for q:=i to j do if a[q]>a[j] then break;
> > >
> > > if q<j then order(q,j-1);
> > > if q>i then order(i,q-1);
> > > write(a[j]);
> > > if j<>n then write(' ');
> > >
> > > end;
> > >
> > >
> > > begin
> > > readln(n);
> > > for I:=1 to n do read(a[i]);
> > > order(1,n);
> > >
> > >
> > > end.
> > >
> > >
But is procedure somebody sed me that i used this array meny times. meby it is this event.
> > So, what do you think is the reason?
> >
> >
> >
> >
> >
> > > > I got "Memory limit exceeded" with this program, however I
> can't
> > > > understand how can it demand more than about 30
> > > >
> > > > var
> > > > n:integer;
> > > > a:array[1..3000] of longint; { 12 kb here }
> > > > i,j:integer;
> > > >
> > > > procedure order(i,j:integer); { In this procedure maximum is
18
> > kb}
> > > > var {becuase recursion maximum
depth
> > here}
> > > > q:integer; {is 3000}
> > > > begin
> > > > {if i=j then
> > > > begin
> > > > write(a[i]);
> > > > exit;
> > > > end; }
> > > >
> > > > for q:=i to j do if a[q]>a[j] then break;
> > > >
> > > > if q<j then order(q,j-1);
> > > > if q>i then order(i,q-1);
> > > > write(a[j]);
> > > > if j<>n then write(' ');
> > > >
> > > > end;
> > > >
> > > >
> > > > begin
> > > > readln(n);
> > > > for I:=1 to n do read(a[i]);
> > > > order(1,n);
> > > >
> > > >
> > > > end.
> > > >
> > > >
No. I don't think
The 'a' array can't be used many times because it's global variable.
I don't use it as a parameter in any procedure or function.
So was in main program but......
Re: But is procedure somebody sed me that i used this array meny times. meby it is this event.
Posted by
dato 23 Dec 2002 18:17
Re: Please explain
But can somebody explain me how can this procedure use the array many
times if this array is a global variable?
Either I'm very stupid or...
I don't kcnow why?
> But can somebody explain me how can this procedure use the array
many
> times if this array is a global variable?
> Either I'm very stupid or...