- Q: Can a Borland Pascal program use static variables
> with more than 64 kilobytes?
- A: No!
- Q: You said *static* variables. Are there other and does it work with them?
- A: Yes, see "Is there a Solution" below, but first read the rest here
to avoid wasting time trying other alternatives, because they
all do not work.
- Q: Does it help to split a large array in several small arrays
(all parts smaller than 64k, but in total larger than 64k) ?
- A: No!
- Q: Does it help to declare some of the variables in a Unit?
- A: No!
- Q: Does it help to declare some in the Implementation Part of a unit?
- A: No!
- Q: Does it help to use the protected mode of Borland Pascal 7 ?
- A: No!
- Q: Are you sure ??
- A: Yes !!
- Q: Why ??
- A: All programs written in Borland Pascal use only one segment for all
variables and the Intel 80xxx processors are limited to 64k per segment.
- Q: That's silly!!
- A: Tell Borland!! (Or Intel or both).
- Q: Is there a Solution ?
- A: Yes! There are two solutions:
1) don't use *STATIC* variables for storing huge amounts of data.
This will allow to store more than 64k in total, but never
more than 64k in *one* array, so yes you must split them but
that alone doesn't help. You must also make them dynamic.
2) use another Compiler: there are a few Pascal compilers
available that are more or less Borland compatible and that
don't have these limitations (they are 32-bit Compilers).
- Q: Why is Borland Pascal not a 32-bit Compiler?
- A: It's too old. Tell Borland you want a new version.
- Q: What is non-static memory?
- A: For example Heap, XMS, EMS, ...
Heap is directly accessible, XMS needs a driver (himem.sys),
EMS too (HIMEM.SYS + EMM386.EXE) and is not commonly available
on all computers, so better use XMS instead of EMS.
- Q: What is the Heap ?
- A: Heap is in real mode all free memory below the 640 kilobyte limit,
in protected mode (available in Borland Pascal 7 only) all free
memory below the 16 Megabyte limit (and usually *ALL* free memory
but we're only talking about Borland Pascal here).
- Q: How can I use the heap?
- A: Memory on the heap can only be accessed with pointers.
Try this example, then adapt the principle to your programs:
type
arr = array [1..30000] of longint; { this is your data }
arrptr = ^arr; { that's a pointer to the data }
var
data : arrptr; { this is such a pointer variable }
begin
if memavail < sizeof(arr) then halt; { check if enough memory available}
new (data); { allocate the memory }
for i := 1 to 30000 do data^[i]:=0; { use it, note the ^ sign here !! }
dispose (data); { release the memory }
end.
Note: instead of data you could also do
var
data : array [1..10000] of arrptr;
- Q: Does this have disadvantages
- A: Yes! It's slower and a bit dangerous.
- Q: Using the heap is dangerous?
- A: Yes!
Double-check that you *always*, I mean really *ALWAYS* allocate
all heap memory before you use it. Otherwise you will see the same
thing happening that we are used to from C programs:
in Windows it's called "General Protection Violation", other
systems call it "Protected Mode Exception #13" or similar.
In real mode the program will usually not cause such an error,
it will just silently overwrite imporant things like other data, the
program itself, other programs, DOS or whatever it finds in memory.
This can cause anything from no negative effect at all to completely
freezing the PC with only the reset button and power switch still
operational. In extreme cases it may also cause data on the hard
disk to be overwritten. That's very unlikeöly but in theory possible.
- Q: How can I use XMS memory?
- A: See http://www.brain.uni-freiburg.de/~klaus/pascal/sources/
for a unit that allows to use XMS.
- Q: What about other Pascal compilers?
- A: Check FPK-Pascal and GNU-Pascal.
Both are free 32-bit Pascal compilers available for DOS
that are more or less Borland compatible.
If you want a Pascal compiler for Linux or OS/2, the two same compilers
are available for these operating systems too plus a few more, see
http://www.brain.uni-freiburg.de/~klaus/pascal/web-list.html
- Q: This sounds as if the FAQ writer doesn't like Borland Pascal, right?
- A: Wrong, I *love* it and use it all the time,
but I *hate* Borland for not offering new versions.
- Q: What about Delphi?
- A: It's not available for DOS,
it's not available for Linux,
it's not availalbe for OS/2.