[comp.lang.pascal] Turbo Pascal/DOS Batch Heap Peculiarity

miller@cogsci.ucsd.EDU (Jeff Miller) (02/16/91)

Here's a peculiarity that's new to us, and we hope someone can help us
understand it.  The symptoms are easy to observe:

1. Compile the following program with Turbo pascal 5.0 or 6.0:

   Program Test;
   Begin
   Writeln(LongInt(HeapOrg));
   End.

2. Now make up two batch files, Test1.bat and Test2.bat

   Each has a single line:    Test

The difference between the batch files is that one ends with a
carriage return (so there is really a null line at the end of the file),
whereas the other batch file ends after the second "t" in Test.

3.  Run the batch files, and they report different HeapOrg's!!!!!!

Anyone know why this is?  (Choose one from column A and one from column B)
    A       B
   DOS     Bug
  Turbo    Feature

Any suggestions on how to handle this problem?
The peculiarity becomes a problem when we run, inside batch files, programs
that use the heap-- if we forget that final carriage return, there goes the
FAT table.

Thanks for any insights you can offer.

Jeff Miller
jomiller@ucsd.edu

dmurdoch@watstat.waterloo.edu (Duncan Murdoch) (02/17/91)

In article <296@cogsci.ucsd.EDU> miller@cogsci.ucsd.EDU (Jeff Miller) writes:

>Here's a peculiarity that's new to us, and we hope someone can help us
>understand it.  The symptoms are easy to observe:
...
>3.  Run the batch files, and they report different HeapOrg's!!!!!!
>
>Anyone know why this is?  (Choose one from column A and one from column B)
>    A       B
>   DOS     Bug
>  Turbo    Feature

It looks to me like a property of DOS, not really a bug or a feature.  The
test program is being loaded at a different place, lower in memory, when
the batch file has no more lines in it.

>Any suggestions on how to handle this problem?
>The peculiarity becomes a problem when we run, inside batch files, programs
>that use the heap-- if we forget that final carriage return, there goes the
>FAT table.

I don't see how this can really be a problem.  Are you relying on having
the heap stay unchanged between calls to your program?  That's very dangerous:
the transient part of COMMAND.COM lives up in high memory, and will stomp on
whatever you've left in the heap, after your program terminates and releases
it.

If you really need shared memory between calls, I don't think there's an easier
way than just putting what you want into a file.  You could also write one of
the programs as a TSR so that its heap is never released, but that's 
a lot of work.

Duncan Murdoch