[fpc-pascal] Managed record questions

Maciej Izak hnb.code at gmail.com
Thu Mar 8 08:20:33 CET 2018

2018-03-08 4:13 GMT+01:00 Ryan Joseph <ryan at thealchemistguild.com>:

> 1) Given the example below we have a template for a standard ref counted
> record. Shouldn’t there be some “meta record” type that implements this
> automatically? I’m thinking about adding this to some types but the idea of
> recreating this same template every time is daunting and records don’t have
> inheritance so there’s no way to capture it once.

Management operators are almost unusable without default field/default
property. How it works you can see here :


the examples can be tested with NewPascal for now. The simplified
inheritance for records can be simulated by "default field", but the main
idea is to use mix of generics/management operators and default field.
"default field" has very long list of potential usages.

> 2) This new feature begs the question why can’t classes be kept on the
> stack OR the heap now like in c++? There’s countless times I allocate a
> class on the heap (because you have to) when I could have kept it on the
> stack and the compiler called some destructor it when it goes out of scope.
> It’s such a common pattern and a shame to be dynamically allocating/freeing
> memory every time. C++ really cleans up a lot of memory garbage by making
> it an option of how your classes are allocated but FPC is stuck in the
> middle with structs/classes being different enough you need to decide once
> and commit to that memory management scheme for all uses.

"ARC" objects are for sure possible to achieve but in other way (by new
feature called concepts). Management operators are intended as base for
nullable types, smart pointers and can be used for ARC classes too but the
real and proper ARC classes should be implemented in other way. In this are
is a lot of R&D - you need to remember that the priority is to keep
backward compatibility - we don't want Delphi NEXTGEN for all modes - the
main advantage of FPC is freedom of choice :)
Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180308/52eb0dbe/attachment.html>

More information about the fpc-pascal mailing list