qp.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
AVAIL.PAS
  Example Contents Index                                    Back
 
PROGRAM avail;
 
{ AVAIL.PAS illustrates the following heap functions:
 
      GetMem    FreeMem    MaxAvail    MemAvail
}
 
CONST
    program_name = 'AVAIL ';
    program_desc = 'demonstrates the heap functions.';
    max_block    = 65520;
 
VAR
    generic_ptr : POINTER;
    request     : LongInt;
    total       : LongInt;
    biggest     : LongInt;
 
BEGIN
 
    Writeln( program_name, program_desc );
    Writeln;
 
    biggest := MaxAvail;
    Writeln( 'Total of ', MemAvail, ' bytes available on heap.' );
    Writeln( 'Largest contiguous block is ', biggest, ' bytes.' );
 
    REPEAT
        Writeln( 'You can allocate up to ', max_block, ' bytes.' );
        Write( 'How large a block of memory do you want to allocate? ');
        Readln( request );
        IF (request > biggest) OR (request > max_block) OR (request < 0)
            THEN Writeln( 'That amount is not available.' );
    UNTIL (request <= biggest) AND
          (request <= max_block) AND
          (request >= 0);
    Writeln( 'Requesting ', request, ' bytes.' );
 
    { Request memory.  Note that we read request into a LongInt in case
      the user types bad data. The value cast below is safe, since the
      REPEAT loop ensures that the value is within range.
    }
    GetMem( generic_ptr, Word(request) );
    Writeln( 'This leaves a total of ', MemAvail, ' bytes, with the ');
    Writeln( 'largest block being ', MaxAvail, ' bytes.');
 
    Writeln( 'Freeing space...' );
    FreeMem( generic_ptr, request );
 
END.