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
With best regards,
Boian Mitov

-------------------------------------------------------
Mitov Software
www.mitov.com
-------------------------------------------------------
*From:* August Oktobar <mailto:augustokto...@gmail.com>
*Sent:* Tuesday, September 23, 2014 10:35 AM
*To:* FPC developers' list <mailto:fpc-devel@lists.freepascal.org>
*Subject:* Re: [fpc-devel] Suggestion: reference counted objects
To somebody (probably Sven):

In FPC there is concept of stack based objects (object) that behave like classes (with inheritance)? Why not just extend this object with support for constructors and destructors, and there is no need for the ARC? On Mon, Sep 22, 2014 at 2:05 PM, Hans-Peter Diettrich <drdiettri...@aol.com <mailto:drdiettri...@aol.com>> wrote:

    Sven Barth schrieb:

        Am 22.09.2014 09:47 schrieb "Michael Schnell"
        <mschn...@lumino.de <mailto:mschn...@lumino.de>


        > Why not use "interface" to add ref-counting to an object ?
        This seems to work nicely even though the name "interface" in
        not "speaking" on that behalf.

        Because you'll need to declare an interface for each class you
        want to have reference counted so that you can access its
        methods, properties, etc.


    This overhead could be eliminated by another syntax extension, like
      TMyARCclass = interface(TObject)
    where the Compiler could allow for implementations of the declared
    methods just as for
      TMyARCclass = class(TObject)
    bridging the gap between traditional (strictly declarative)
    interfaces and classes (including implementations), with or
    without ARC.

    DoDi

    _______________________________________________
    fpc-devel maillist  - fpc-devel@lists.freepascal.org
    <mailto:fpc-devel@lists.freepascal.org>
    http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

------------------------------------------------------------------------
_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel


_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

_______________________________________________
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply via email to