7.2.3 Turbo Pascal compatibility mode

When you compile a program with the -Mtp switch, the compiler will attempt to mimic the Turbo Pascal compiler in the following ways:

Remark The MemAvail and MaxAvail functions are no longer available in Free Pascal as of version 2.0. The reason for this incompatibility follows:

On modern operating systems, 1 the idea of ”Available Free Memory” is not valid for an application. The reasons are:

1.
One processor cycle after an application asked the OS how much memory is free, another application may have allocated everything.
2.
It is not clear what ”free memory” means: does it include swap memory, does it include disk cache memory (the disk cache can grow and shrink on modern OS’es), does it include memory allocated to other applications but which can be swapped out, etc.

Therefore, programs using MemAvail and MaxAvail functions should be rewritten so they no longer use these functions, because it does not make sense any more on modern OS’es. There are 3 possibilities:

1.
Use exceptions to catch out-of-memory errors.
2.
Set the global variable ”ReturnNilIfGrowHeapFails” to True and check after each allocation whether the pointer is different from Nil.
3.
Don’t care and declare a dummy function called MaxAvail which always returns High(LongInt) (or some other constant).

1The DOS extender GO32V2 falls under this definition of ”modern” because it can use paged memory and run in multitasked environments.