From f79d7d622ac575a37089a9eac53a39e3fbe23ebe Mon Sep 17 00:00:00 2001 From: slederer Date: Fri, 19 Sep 2025 22:17:05 +0200 Subject: [PATCH] doc: add section on new/newOrNil/dispose --- doc/pascalprogramming.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/doc/pascalprogramming.md b/doc/pascalprogramming.md index 1c53cc1..df5d3fd 100644 --- a/doc/pascalprogramming.md +++ b/doc/pascalprogramming.md @@ -103,6 +103,16 @@ Tridora-Pascal only supports the _break_ statement at the moment. The _exit_ statement can be used to exit the current procedure or function. If it is a function, the return value of the function is undefined if _exit_ is used before a return value is assigned. + +## Dynamic Memory Allocation +Memory allocation generally works as expected with the *new* and *dispose* special procedures. The variant of *new* with two parameters that is specified in Wirth Pascal is not supported (partial allocation of a variant record). Instead, there is a variant of *new* that has a second parameter for allocating strings (see above). + +If heap allocation fails, *new* does not return and instead causes a runtime error. To avoid this, a different special procedure called *newOrNil* can be used. This procedure sets the pointer +variable to *niL* if heap allocation fails. + +The function *MemAvail* returns the number of free bytes on the heap. It does not guarantee that this amount of memory can be allocated with *new*, because heap space can be fragmented. +The function *MaxAvail*, which exists in some versions of Turbo Pascal and returns the size of the largest contiguous block of available heap memory, is not (yet) implemented. + ## I/O I/O handling in Tridora Pascal is mostly compatible with other Pascal dialects when reading/writing simple variables from/to the console. There are big differences when opening/reading/writing files explicitly.