Unexpected heap overflow in protected mode program compiled by BP7 
Author Message
 Unexpected heap overflow in protected mode program compiled by BP7

I use Borland Pascal 7.0 and comile protected mode SW.

Below simple program crashes with heap overflow error even when there is
enough DPMI memory available. Does anyone has similar experinece, is
there a workaround?

{$F+,O+} Program HeapTest; {$M 65520,0,655360}

Const Max_X=1650;

type
Ts=string[255];
TMatrix=array [0..Max_X] of ^Ts;

const ii=100;
var i,x:integer;M:array[1..ii] of ^TMatrix;

Begin
Writeln(MaxAvail,'  ',MemAvail);
for i:=1 to ii do
begin
new(M);
for x:=0 to Max_X do New(M^[x]);
Writeln(MaxAvail,'  ',MemAvail);
end;
Readln;
End.

--
Posted via http://www.*-*-*.com/



Mon, 28 Feb 2005 19:39:39 GMT  
 Unexpected heap overflow in protected mode program compiled by BP7
Quote:

> I use Borland Pascal 7.0 and comile protected mode SW.

> Below simple program crashes with heap overflow error even when there is
> enough DPMI memory available. Does anyone has similar experinece, is
> there a workaround?

> {$F+,O+} Program HeapTest; {$M 65520,0,655360}

> Const Max_X=1650;

> type
> Ts=string[255];
> TMatrix=array [0..Max_X] of ^Ts;

> const ii=100;
> var i,x:integer;M:array[1..ii] of ^TMatrix;

> Begin
> Writeln(MaxAvail,'  ',MemAvail);
> for i:=1 to ii do
> begin
> new(M);

      ^Pointer variable expected.

Quote:
> for x:=0 to Max_X do New(M^[x]);
> Writeln(MaxAvail,'  ',MemAvail);
> end;
> Readln;
> End.

With BP, you can allocate about 59330 Strings (max. 16MB RAM).

I guess your program is supposed to allocate about 42MB RAM. This is not
possible with BP, you might want to use newer compilers, such as
FreePascal or GNU-Pascal.

Wolf



Mon, 28 Feb 2005 20:41:55 GMT  
 Unexpected heap overflow in protected mode program compiled by BP7

Dear Wolf,

It isn't about strings, sligthly modifying the source:
{$F+,O+} Program HeapTest; {$M 65520,0,655360}

Const Max_X=1650;

type
{ Ts=string[255];}
TMatrix=array [0..Max_X] of pointer{^Ts};

const ii=10000;
var i,x:integer;M:array[1..ii] of ^TMatrix;

Begin
Writeln(MaxAvail,'  ',MemAvail);
for i:=1 to ii do
begin
new(M);
{for x:=0 to Max_X do New(M^[x]);}
Writeln(MaxAvail,'  ',MemAvail);
end;
Readln;
End.

it still crashes. By the way it is only a small demo to demonstrate the
bug in BP, unfortunately I am stuck to BP with a huge program, which
would be very hard to port to other compiler.

Thanks for the reply though,
Gyula

--
Posted via http://dbforums.com



Mon, 28 Feb 2005 21:39:03 GMT  
 Unexpected heap overflow in protected mode program compiled by BP7

Quote:

> it still crashes. By the way it is only a small demo to demonstrate the
> bug in BP, unfortunately I am stuck to BP with a huge program, which
> would be very hard to port to other compiler.

Just out of curiousity, what where the problems you encountered/expect with
e.g. FPC ?


Mon, 28 Feb 2005 23:45:13 GMT  
 Unexpected heap overflow in protected mode program compiled by BP7

Quote:

> Dear Wolf,

> It isn't about strings, sligthly modifying the source:
> {$F+,O+} Program HeapTest; {$M 65520,0,655360}

> Const Max_X=1650;

> type
> { Ts=string[255];}
> TMatrix=array [0..Max_X] of pointer{^Ts};

> const ii=10000;
> var i,x:integer;M:array[1..ii] of ^TMatrix;

> Begin
> Writeln(MaxAvail,'  ',MemAvail);
> for i:=1 to ii do
> begin
> new(M);
> {for x:=0 to Max_X do New(M^[x]);}
> Writeln(MaxAvail,'  ',MemAvail);
> end;
> Readln;
> End.

> it still crashes. By the way it is only a small demo to demonstrate the
> bug in BP, unfortunately I am stuck to BP with a huge program, which
> would be very hard to port to other compiler.

This program still does _not_ compile (M is not a pointer, it is an
array)! So I can't reproduce a bug. What exactly is your problem? Can
you post a program that compiles? (then copy+paste, please)

If your problem is compiling:
type MatrixOfPMatrix=array[1..ii] of ^TMatrix;
var m: ^MatrixOfPMatrix;

Pascal is not C, an array is not a pointer!

Wolf



Tue, 01 Mar 2005 01:59:29 GMT  
 Unexpected heap overflow in protected mode program compiled by BP7



Quote:

> I use Borland Pascal 7.0 and comile protected mode SW.

> Below simple program crashes with heap overflow error even when there
is
> enough DPMI memory available. Does anyone has similar experinece, is
> there a workaround?

OK here's the solution. (tested)
I had to modify you program a little for the faulty adressing of M[..]
But the secret is in
Hheaplimit and Heapblock
Now you can use 64 mb of memory.

--
Femme

{$F+,O+} Program HeapTest; {$M 65520,0,655360}

Const Max_X=1650;

type
Ts=string[255];
TMatrix=array [0..Max_X] of ^Ts;

const ii=100;
var i,x:integer;
 M:array[1..ii] of ^TMatrix;

Begin
  Heaplimit:=1024*8;
  Heapblock:=1024*48;
Writeln(MaxAvail,'  ',MemAvail);
for i:=1 to ii do
begin
  new(M[i]);
  for x:=0 to Max_X do New(M[i]^[x]);
Writeln(i:3,':',MaxAvail,'  ',MemAvail);
end;
Readln;
End.



Tue, 01 Mar 2005 03:08:55 GMT  
 Unexpected heap overflow in protected mode program compiled by BP7

Wolf,

Of course it compiles. Yes M is an array not a pointer, but every array
member of M is a pointer (M:array[1..ii] of ^TMatrix;) so New(M) is a
valid operation. And I do know the difference between Pascal and C.

My problem is that it crashes even though I still have DPMI memory
according to MemAvail or MaxAvail, so it is a bug of BP.

Marco,

In the program that I encountered this bug needs a lot of memory to be
accessed by pointers. It can keep up to some point, but then randomly it
crashes with heap overflow.

Gyula

--
Posted via http://dbforums.com



Tue, 01 Mar 2005 02:55:19 GMT  
 Unexpected heap overflow in protected mode program compiled by BP7

Quote:

> Wolf,

> Of course it compiles. Yes M is an array not a pointer, but every array
> member of M is a pointer (M:array[1..ii] of ^TMatrix;) so New(M) is a
> valid operation. And I do know the difference between Pascal and C.

Hmm, it shouldn't be. M is the array, and that isn't a pointer type.
FPC doesn't eat it (can't BP under *nix),

Quote:
> My problem is that it crashes even though I still have DPMI memory
> according to MemAvail or MaxAvail, so it is a bug of BP.

Not really, it is a flaw of the 286 DPMI system, but it can be worked around
by the RTL. Because memory was expensive in '92 (release date BP), the
default values are just somewhat conservative.

Quote:
> Marco,

> In the program that I encountered this bug needs a lot of memory to be
> accessed by pointers. It can keep up to some point, but then randomly it
> crashes with heap overflow.

This is probably due to the maximal selector limit, and one can stall the
problem till 64 MB, by the methods Femme posted, which has been discussed
and tested before.

But that wasn't the question. The question is why a different compiler
couldn't compile your program :-)



Tue, 01 Mar 2005 04:30:07 GMT  
 Unexpected heap overflow in protected mode program compiled by BP7



Quote:

> > Wolf,

> > Of course it compiles. Yes M is an array not a pointer, but every
array
> > member of M is a pointer (M:array[1..ii] of ^TMatrix;) so New(M) is a
> > valid operation. And I do know the difference between Pascal and C.

> Hmm, it shouldn't be. M is the array, and that isn't a pointer type.
> FPC doesn't eat it (can't BP under *nix),

Very strange indeed. When I tried to compile the program in BP 7, it
refused to compile
New(M); since M is not a pointer variable.

Quote:
> > My problem is that it crashes even though I still have DPMI memory
> > according to MemAvail or MaxAvail, so it is a bug of BP.

Not a bug. Problem is that the program is running out of selectors. See
the solution in my other posting.

Quote:
> Not really, it is a flaw of the 286 DPMI system, but it can be worked
around
> by the RTL. Because memory was expensive in '92 (release date BP), the
> default values are just somewhat conservative.

> > Marco,

> > In the program that I encountered this bug needs a lot of memory to
be
> > accessed by pointers. It can keep up to some point, but then randomly
it
> > crashes with heap overflow.

Be careful. Memavail and Maxavail do not report the correct amount of
available memory. Not a BP bug, but a Windows feature [;-}

Quote:

> This is probably due to the maximal selector limit, and one can stall
the
> problem till 64 MB, by the methods Femme posted, which has been
discussed
> and tested before.

> But that wasn't the question. The question is why a different compiler
> couldn't compile your program :-)

Huh, what compiler?

Femme



Tue, 01 Mar 2005 08:16:21 GMT  
 Unexpected heap overflow in protected mode program compiled by BP7

Quote:
>This is probably due to the maximal selector limit, and one can stall
>the problem

till 64 MB, by the methods Femme posted, which has been discussed and
tested before.

I am not able to find these discussions, can you direct me how to locate
them, I am very interested.

Quote:
>But that wasn't the question. The question is why a different
>compiler couldn't

compile your program :-)

I tried to use Free Pascal, but my program does extensive hardware
access and has some assembler as well. There are some differencies as
far as I remember from BP. So I think it could be compiled, but it would
be a lot of work, and a lot more testing.

--
Posted via http://dbforums.com



Tue, 01 Mar 2005 15:23:20 GMT  
 Unexpected heap overflow in protected mode program compiled by BP7

Quote:

>>This is probably due to the maximal selector limit, and one can stall
>>the problem
> till 64 MB, by the methods Femme posted, which has been discussed and
> tested before.

> I am not able to find these discussions, can you direct me how to locate
> them, I am very interested.

See the example that Femme posted two days ago, and search for "heapblock" in
this group on groups.google.com

Quote:
>>But that wasn't the question. The question is why a different
>>compiler couldn't
> compile your program :-)

> I tried to use Free Pascal, but my program does extensive hardware
> access and has some assembler as well. There are some differencies as
> far as I remember from BP. So I think it could be compiled, but it would
> be a lot of work, and a lot more testing.

True. But if it is somewhat localized, it often isn't that bad, since it
can remain Dos in first approx.


Tue, 01 Mar 2005 18:50:41 GMT  
 Unexpected heap overflow in protected mode program compiled by BP7

Thanks Marco

--
Posted via http://dbforums.com



Tue, 01 Mar 2005 19:35:42 GMT  
 Unexpected heap overflow in protected mode program compiled by BP7



Quote:

> >This is probably due to the maximal selector limit, and one can stall
> >the problem
> till 64 MB, by the methods Femme posted, which has been discussed and
> tested before.

> I am not able to find these discussions, can you direct me how to
locate
> them, I am very interested.

The discussion was in this group, but your right, it has disappeared from
the server.
Look for it in Google / newgroups. I believe the discussion was called
"More memory"

Femme



Tue, 01 Mar 2005 21:38:46 GMT  
 Unexpected heap overflow in protected mode program compiled by BP7

Dear Femme,

I have already found the article, thank you. And it did solve my
problem.

Gyula

--
Posted via http://dbforums.com



Tue, 01 Mar 2005 23:31:36 GMT  
 Unexpected heap overflow in protected mode program compiled by BP7
I come late, but in:

Quote:
> {$F+,O+} Program HeapTest; {$M 65520,0,655360}

> Const Max_X=1650;

> type
> { Ts=string[255];}
> TMatrix=array [0..Max_X] of pointer{^Ts};

> const ii=10000;
> var i,x:integer;M:array[1..ii] of ^TMatrix;

> Begin
> Writeln(MaxAvail,'  ',MemAvail);
> for i:=1 to ii do
> begin
> new(M);
> {for x:=0 to Max_X do New(M^[x]);}
> Writeln(MaxAvail,'  ',MemAvail);
> end;
> Readln;
> End.

an array of 10000 pointers is assigned memory 10000 times; that are
100.000.000 pointers and isn't that too much even for 64 MB ?

Georg.



Sun, 06 Mar 2005 05:05:21 GMT  
 
 [ 17 post ]  Go to page: [1] [2]

 Relevant Pages 

1. Getting TP to compile a DOS program in Protected Mode

2. BP7: Heap overflow with Memavail>4MB

3. BP7: DLL in DOS protected mode program

4. BP7 protected mode chain to another program

5. program tracing in BP7, protected mode

6. Compiling in Protected Mode

7. protected mode compiling

8. 'Delphi does dos' - compile and debug BP7 protected mode programs under D1.

9. BP7 + Protected mode apps + Windows 95/98 = slowdown

10. BP7 Protected Mode Problems

11. Allocating memory under protected mode (BP7)

12. Protected Mode and DMA with BP7

 

 
Powered by phpBB® Forum Software