100% agree, although although smart pointers also can already be implemented in
Delphi with anonymous methods.
I wanted to mention the possibility actually in my post.
For good smart pointer however we also will need implicit casting, operator
overloading and few other features, but it surely is an option.
As for STL, we actually already have implemented some aspects of it in
Mitov.Runtime (Free library) for Delphi, and will be doing more.
I am huge fan of STL/boost and the concept based development, and I use some
aspects of it even in Delphi (to the extend the language and the generics
allow).
With best regards,
Boian Mitov
-------------------------------------------------------
Mitov Software
www.mitov.com
-------------------------------------------------------
From: Nikolay Nikolov
Sent: Wednesday, September 24, 2014 3:34 PM
To: fpc-devel@lists.freepascal.org
Subject: Re: [fpc-devel] Suggestion: reference counted objects
On 09/23/2014 08:47 PM, Boian Mitov wrote:
This is a valid point.
The only downside is that the object will every time do a deep copy versus a
shallow (pointer only) copy. Deep copy is very, very expensive operation.
Adding ref. counting to objects is probably equivalent of one interlocked
assembly instruction, so a very small difference, probably not even measurable.
Copy of a large object can take a large memory transfer, and will also
reserve memory for each copy, thus significantly increasing memory.
While both approaches have something going for them, they are not total
subside for each other.
Yes, but if you have compiler support for objects with automatic calls of
constructors/destructor/copy constructor/assignment operator (like in C++
classes), and if you also have generics support for objects, you can make a
generic smart pointer object type that adds reference counting to any class.
And then the regular class references will serve as weak references. Exactly
like C++:
http://www.boost.org/doc/libs/1_56_0/libs/smart_ptr/smart_ptr.htm
What's more important is that we can extend objects this way, without breaking
backward compatibility. But, unfortunately, it's a huge slippery slope from
there, as anyone, who has dealt with C++ STL error messages knows:
http://pascalg.wordpress.com/2008/02/24/stl-error-messages-are-so-great/
Nikolay
_______________________________________________
fpc-devel maillist - fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel