new D2.0 + C++ language

Weed resume755 at mail.ru
Fri Mar 20 02:38:42 PDT 2009


Christopher Wright пишет:

>>>>>>> And regarding performance, eventually it will come a lot from a good
>>>>>>> usage of multiprocessing,
>>>>>> The proposal will be able support multiprocessing - for it provided a
>>>>>> references counting in the debug version of binaries. If you know the
>>>>>> best way for language *without GC* guaranteeing the existence of an
>>>>>> object without overhead - I have to listen!
>>>>> You cannot alter the reference count of an immutable variable.
>>>> Why?
>>> Because it's immutable!
>>>
>>> Unless you're storing a dictionary of objects to reference counts
>>> somewhere, that is. Which would be hideously slow and a pain to use. Not
>>> that reference counting is fun.
>>
>>
>> Precisely. I wrote the cost for that: 1 dereferencing + inc/dec of
>> counter.
> 
> It's more expensive than dereferencing. If your const object points to
> its reference count, then the reference count is also const, so you
> can't alter it.

It is designed not so. There will be a hidden dereferencing:

const ref Obj object -> struct{ Obj* object;    -> Obj object;
		       	        int counter; };

For all objects will be created such structs. "this" inside the object
returns ptr to struct. Any appeal by reference to an object would cause
such dereferencing.

Creating reference to object in a code block will cause an increase in
the counter. Destruction of reference will cause an automatic decrease
in the counter.

By the way, upon arrival into the try{} it will save values of reference
counters for the correct exit if exception will be generated.

> 
> So the best you can possibly do is one hashtable lookup for every time
> you alter the reference count for a non-mutable variable. That is a huge
> overhead, much more so than garbage collection.



More information about the Digitalmars-d mailing list