Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Sven Barth via fpc-pascal
Am 09.03.2018 05:14 schrieb "Ryan Joseph" : > On Mar 9, 2018, at 10:32 AM, Michael Van Canneyt wrote: > > Why don't you use objects ? No-one has obsoleted this, and you get what you > want: an object that can be allocated on the stack or on the heap. Object is just for backwards compatibility

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Ryan Joseph
> On Mar 9, 2018, at 10:32 AM, Michael Van Canneyt > wrote: > > Why don't you use objects ? No-one has obsoleted this, and you get what you > want: an object that can be allocated on the stack or on the heap. Object is just for backwards compatibility right? Does it support new features like

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Michael Van Canneyt
On Fri, 9 Mar 2018, Ryan Joseph wrote: On Mar 9, 2018, at 3:55 AM, Graeme Geldenhuys wrote: My first question What is a managed record? My second question Why would I need it? My third question. What is different compared to a "normal record" and compared to

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Ryan Joseph
> On Mar 9, 2018, at 3:55 AM, Graeme Geldenhuys > wrote: > > My first question > What is a managed record? > > My second question > Why would I need it? > > My third question. > What is different compared to a "normal record" > and compared to FPC's Object data ty

[fpc-pascal] ANN: Generics.Collections 2.0

2018-03-08 Thread Maciej Izak
I'm pleased to finally announce next release of rtl-generics aka Generics.Collections 2.0 version for trunk available in trunk ;) version for 3.0.4 available at : https://github.com/maciej-izak/generics.collections What is new: * New collections: - TSortedList - THashSet - TAVLTreeMa

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Graeme Geldenhuys
On 2018-03-08 03:13, Ryan Joseph wrote: So in the trunk we have managed records now which is a brilliant addition and long overdue. Some questions these bring up: My first question What is a managed record? My second question Why would I need it? My third question.

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Ryan Joseph
> On Mar 8, 2018, at 8:28 PM, Sven Barth via fpc-pascal > wrote: > > This is not an oversight, but an explicit design decision of the language. Do you recall what the history was of this choice? I can remember using the “new" keyword on objects but I don’t remember much more (I didn’t go ful

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Sven Barth via fpc-pascal
Am 08.03.2018 12:51 schrieb "Ryan Joseph" : > On Mar 8, 2018, at 5:42 PM, Sven Barth via fpc-pascal < fpc-pascal@lists.freepascal.org> wrote: > > You are supposed to use try...finally for this. The finally-block is always executed when the try-block is left no matter if it's by reaching the end,

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Ryan Joseph
> On Mar 8, 2018, at 5:42 PM, Sven Barth via fpc-pascal > wrote: > > You are supposed to use try...finally for this. The finally-block is always > executed when the try-block is left no matter if it's by reaching the end, > calling exit or by an exception. > But my greater point is why ar

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Sven Barth via fpc-pascal
Am 08.03.2018 09:44 schrieb "Ryan Joseph" : 2) We need to remember to call Free() at the end of the function and take precaution to not exit early and leak memory (maybe even using a goto to break out of nested loops or nested functions, who knows). You are supposed to use try...finally for this

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Sven Barth via fpc-pascal
Am 08.03.2018 08:33 schrieb "Maciej Izak" : No, this doesn't beg the question, because Object Pascal classes are > designed in the principle to reduce on the heap. Changing this would not > only mean quite some changes in the compiler/RTL with no real gain, but it > would also change a core aspec

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Martin Schreiber
On 03/08/2018 10:16 AM, Ryan Joseph wrote: > > > > I know this is how it is and not likely to change I’m just pointing it out. In MSElang objects and classes have been unified, they can be allocated on stack or on heap. They also have hooks for initialization and finalization which can be used

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Ryan Joseph
> On Mar 8, 2018, at 4:00 PM, Maciej Izak wrote: > > Small ad of mORMot (main author Arnaud Bouchez aka ab) : > > with SynCommons module you have nice utils for such things: > > procedure MyProc; > var > list: TList; > begin > with TAutoFree.One(list, TList.Create) do > begin > lis

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Maciej Izak
2018-03-08 9:13 GMT+01:00 Ryan Joseph : > The more efficient approach would clearly be something like: > > procedure MyProc; > var > list: stack TList; // assume this allocates us on the stack like a > record > begin > list.Clear; // there’s no Create call so init the class some ho

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Ryan Joseph
> On Mar 8, 2018, at 3:12 PM, Michael Van Canneyt > wrote: > > You can still use objects. I guess I can go back to objects and use pointers to objects when I want classes? I don’t know if objects even have all the same functionality of classes, and aren’t they for backwards compatibility an

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Ryan Joseph
> On Mar 8, 2018, at 2:43 PM, Ryan Joseph wrote: > > In many cases I don’t actually need anything on the heap and a record could > be used instead but because of limitations on records in Pascal I need a full > class. Doing the ARC route is just solving a problem I created by the fact I > us

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Maciej Izak
2018-03-08 9:12 GMT+01:00 Michael Van Canneyt : > You can still use objects. +1. in most of cases this is enough -- Best regards, Maciej Izak ___ fpc-pascal maillist - fpc-pascal@lists.freepascal.org http://lists.freepascal.org/cgi-bin/mailman/list

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Ryan Joseph
> On Mar 8, 2018, at 2:20 PM, Maciej Izak wrote: > > Management operators are almost unusable without default field/default > property. How it works you can see here : > > https://github.com/maciej-izak/PascalSmartPointers > > the examples can be tested with NewPascal for now. The simplified

Re: [fpc-pascal] Managed record questions

2018-03-08 Thread Michael Van Canneyt
On Thu, 8 Mar 2018, Ryan Joseph wrote: On Mar 8, 2018, at 1:48 PM, Sven Barth via fpc-pascal wrote: You could use an include file containing both the declaration and implementation controlled by compiler defines together with a macro for the type name. That’s a nice trick. If those re