|
![](/i/fill.gif) |
On 10/1/2012 6:29, Warp wrote:
> Darren New<dne### [at] san rr com> wrote:
>>> Since the compiler can track when the object goes out of scope,
>
>> But C++ can't do this
>
> Of course it can. That's the very essence of RAII.
Only for stuff I allocate on the stack and which I don't pass by value.
>> , which is why you wind up with all kinds of smart
>> pointer types. You can make it work, but you can also get it wrong.
>
> You are confusing tracking the scope of an object with tracking references
> that point to a dynamically allocated object. Those are completely different
> things.
I'm not confusing them at all. I'm simply pointing out that scope-tracking
doesn't work for heap-allocated objects.
>> If you take a mutex, and pass it to a subroutine by value, you've just
>> screwed your lock
>
> Which is why mutex objects cannot be passed by value (ie. they have their
> copy constructors and copy assignment operators disabled).
And you deal with mutex objects in the heap how?
> (If you really need to pass such an object as a function parameter, then
> you can do it by using *move* semantics rather than *copy* semantics.)
And when you move it back...?
> (The reason is that it uses move semantics rather than copy semantics.)
But nothing enforces that.
>> Singularity does it by making you declare the function like this:
>> void xyz([claimed] tracked one, tracked two) { destroy one; }
>> (or some such syntax)
>
> What exactly stops the compiler from generating the destructor call
> automatically? Why exactly do you have to write it explicitly?
Because you might want to destruct something somewhere other than when
returning from a block, I suppose. You don't want to destruct some object
like that when you dispose the penultimate reference, but you do want to
destruct it when you dispose the ultimate reference. You need some way of
storing it in the heap, as well as the ability to reliably pass references
to stack objects downward in the call tree but not return them upwards.
Remember that singularity supports multiple languages, too.
--
Darren New, San Diego CA, USA (PST)
"They're the 1-800-#-GORILA of the telecom business."
Post a reply to this message
|
![](/i/fill.gif) |