[fpc-devel] Suggestion: reference counted objects
ppopov99 at gmail.com
Sun Sep 21 20:13:33 CEST 2014
1. I mostly care for performance, so I will start here: They add overheads
which in certain situations can be very bad. These can come in many
shapes, including additional memory for the reference counter, creating
cache incoherence when doing local object assignments (which would cause
some function calls on various patches of memory), the actual inc/dec
which would probably be in the form of virtual functions (which may cause
pointer chasing), etc.
2. There is no need to force such behavior for all objects: if you want
reference counting, work with interfaces, or make a special derived object
3. They break the semantics of existing code.
4. You will mess up code which is tuned to work in certain ways with the
heap. For example, I routinely allocate huge chunks of instances the same
class to avoid the performance penalty of mallocs, to avoid heap
fragmentation and to decrease cache misses in loops. These objects are
managed by a custom heap manager via NewInstance/FreeInstance/Destroy. Why
on earth should the compiler tell me how to manage such situations, when
clearly I have something very specific in mind which does not fit the
general scheme of things?
5. Reference counting does not eliminate memory leaks, the trivial
situation being a loop assignements a=b, b=c, c=a.
6. You may want control on the deallocation order of classes.
7. Last but not least, you make the language inconsistent. It allows
direct pointer mallocs which could be turned into classes, arrays, etc.
Forcing different behavior for classes will create an inconsistent
structure of the language. If you want reference counting in a consistent
way you have to ban getmem/freemem. Either all memory operations are
type-managed (no thanks), or you give an option for reference counting
which is contained in the grammar of the language (e.g. inheriting a
class). Forcing a bad mix is, as I said earlier, uniquely bad idea.
In summary, if it is already there, why force it on all, change the
language and create a mess?
On Sat, 20 Sep 2014 14:42:53 +0300, Sven Barth
<pascaldragon at googlemail.com> wrote:
> On 20.09.2014 13:11, Peter Popov wrote:
>> Please do not reference count TObject. This is a uniquely bad and
>> unnecessary idea. I will switch to ANSI C if you guys do it
> Please enlighten me why you think it is bad. Give reasons and don't be
> like "a farmer doesn't eat what he doesn't know" (rough translation of a
> German proverb).
> And just to give you a reason *for* reference counted objects: they
> would finally allow to use operator overloads on classes, because then
> temporarily created objects are created correctly (think about an
> expression like "a * (b + c)" with classes).
> Please also note that I said that I don't consider them to be the holy
> grail especially considering that I know of some of the technial
> problems one needs to face when implementing them in an already existing
> fpc-devel maillist - fpc-devel at lists.freepascal.org
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
More information about the fpc-devel