D/Objective-C, extern (Objective-C)

Michel Fortin michel.fortin at michelf.ca
Mon Jun 24 13:18:51 PDT 2013


On 2013-06-24 17:53:40 +0000, Walter Bright <newshound2 at digitalmars.com> said:

> On 6/24/2013 6:27 AM, Michel Fortin wrote:
>> Finally, there is a couple of features that were added to Objective-C 
>> since then
>> that should be added to the todo list to keep feature parity. Some of those, if
>> implemented right, could benefit the rest of D too. For instance: ARC 
>> (automatic
>> reference counting) which is becoming a must in Objective-C.
> 
> Arc has very serious problems - I don't see how it can be done and be 
> memory safe without adding extensive pointer annotations. The general 
> problem is someone taking the address of a member of the reference 
> counted object. The rc goes to zero, the objects gets deleted, and 
> there's that dangling pointer to it.

That's not a so big problem: just disallow taking pointers to member 
variables inside of reference-counted memory blocks. At least in SafeD. 
This is a quite rare thing to do in Objective-C anyway, I'd be 
surprised if it bothered anyone.

And I don't think it is very common in D either. Either way, if D was 
to implement ARC for its own memory allocator instead of the current GC 
(which would be great) there's noting to prevent implementing it so 
that reference counts could be incremented from the middle address of a 
memory block, it'd be quite easy in fact, and quite necessary too 
because of the way arrays work.

Usually, the most annoying part of ARC is retain cycles, especially 
implicit ones created by blocks (Objective-C's delegate literals).

-- 
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca/



More information about the Digitalmars-d-announce mailing list