[fpc-pascal] Why use pointers to arrays?

Graeme Geldenhuys graemeg.lists at gmail.com
Sun Oct 11 18:30:28 CEST 2009


On 11/10/2009, Andrew Brunner <andrew.t.brunner at gmail.com> wrote:
>  FPC forces the ^ operator while accessing structures as pointers.
>  Delphi didn't force it and I even suspect that memory leaks can result
>  in NOT using the ^ to denote the reference to the pointer rather than
>  the pointer itself.

This was just discussed in another thread. This is not always forced by FPC.
eg:

var
  S:  TMyArray;
  pS: ^TMyArray;

then use them as follows:

  S[2]
  pS[2]

Both work just fine without dereferencing the second line. Weird
behaviour, but true.


>  Lastly, passing by reference rather than by value is much faster.
>  Since copies need not be made when entering a method when entered

OK, so this is only a benefit then if you use Arrays. If I had to use
a simple data class (class with no methods), then I can simply pass it
as normal or via 'var' parameters and get the same result as you
mentioned.


-- 
Regards,
  - Graeme -


_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/



More information about the fpc-pascal mailing list