[fpc-pascal] Stack alias for ARC like memory management?

Ryan Joseph ryan at thealchemistguild.com
Wed Apr 25 10:50:54 CEST 2018

> On Apr 25, 2018, at 3:22 PM, Marco van de Voort <marcov at stack.nl> wrote:
> I think if you want to pursue this, you must be much more concrete. Both the
> benefits and the potential pitfalls.

What are the potential pitfalls? Sven pointed out passing around pointers but don’t we know better than this since we’re using Pascal and know how memory works? If a function takes a class as a parameter don’t you know if the function is going to store it for later or not? Even if the class is on the heap I don’t just pass it another function and then forget about (creating a leak) or clean it up immediately because I think the function owns it now.

It’s basically like doing this right? I do this often to prevent copying but I just learned this year about the “constref” keyword which cleans up the @ symbol (another small optimization which I really appreciate being added).

  rec: TSomeRec;

I know DoThis isn’t going to keep the pointer alive for later or I would never do this. Since the keyword is an explicit opt-in I assume the programmer really does know they’re doing because they are 100% certain they want the class to only exist for the lifetime of the scope.

In fact adding the keyword is like an explicit contract to the compiler that you INSIST the class be destroyed at the end of the scope. That’s the entire purpose of it, eg. “kill me at the end of scope so I don’t have to do this myself later”. :) If the programmer was smart enough to tell the compiler that we can assume they won’t be stupid and pass it around to some random function they don’t trust.

	Ryan Joseph

More information about the fpc-pascal mailing list