Page 1 of 1

Overhead of Record Parameters

Posted: Mon Apr 15, 2019 2:47 am
by gray

Code: Select all

MODULE M10;

  TYPE
    P = POINTER TO R;
    R = RECORD END;

  VAR
    p: P;
    r: R;

  PROCEDURE P1(r: R);
  END P1;
  
  PROCEDURE P2(VAR r: R);
  END P2;
  
  PROCEDURE P3(p: P);
  END P3;
  
BEGIN
  P1(r);
  P2(r);
  P3(p)
END M10.
What are the differences in the overhead when calling the procedures? I would assume they are minimal, in particular for P2 and P3, but also for P1, as the value record parameter is read-only, hence no value copying needs to take place (in the original PiO of 1992, the authors recommend using VAR parameters if performance is important -- and it was the same for Modula-2, IIRC -- but I would assume that's the (or a) reason for the read-only rule in the current language version).

Re: Overhead of Record Parameters

Posted: Mon Apr 15, 2019 11:43 am
by cfbsoftware
The call to P3 is the most efficient (just). The calls to P1 and P2 generate identical code for the reason you state.