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

Ryan Joseph ryan at thealchemistguild.com
Wed Apr 25 08:34:32 CEST 2018



> On Apr 25, 2018, at 12:59 PM, Sven Barth via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> 
> No. This would more often than not lead to accidents were users pass such an instance to some outer code (it doesn't even need to the routine with the stack object, but some third party routine that for some reason stores the pointer and is called from that routine) and then will trigger an exception in the best case or hard to debug errors in the worst case. 

I assume if programmers care enough about performance they’re planning out memory usage by stack vs heap they know not to do that. The pointer is only alive for the duration of the scope. I thought this was a good idea because it explicitly lets you opt in when know you really need it and it’s discreet.

If c++ programmers know not to do that why don’t Pascal programmers? There’s endless ways to screw yourself with memory in general (especially in c++) but we still find a way.

> 
> The memory model of classes in Object Pascal is heap based. Changing that is asking for trouble and I for one don't even want to fiddle around with that, because I don't see any real benefit in it (and yes I daily work with C++) that couldn't also be solved with a working ARC system. 
> 

But putting classes on the stack is a core feature which is very well used and great for performance (why people still use c++ for games). Why isn’t that useful? So many of the stupid memory management patterns we use in Pascal could be replaced if the language had some good support for it. C++ does it and on the other end ARC languages do it for you, albeit at a performance loss. 

Maybe I don’t know who the market for Pascal is anymore because to me it seems like a legacy language which is being kept alive by a small group of hobbyist but never actually used for any real world applications. I’ve already pretty much given up writing Mac apps with Pascal because it’s so hard to keep up to date and Swift is better than Objective-C but I’d like to keep using it for games if I can. At the end of the day I really want to be able to say at least Pascal is a good low-level language for writing fast code but in the face of C++ that’s kind of dubious claim.

Regards,
	Ryan Joseph



More information about the fpc-pascal mailing list