DIP60: @nogc attribute

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 17 13:30:51 PDT 2014


On Thu, 17 Apr 2014 15:55:10 -0400, Walter Bright  
<newshound2 at digitalmars.com> wrote:

> On 4/17/2014 12:41 PM, Steven Schveighoffer wrote:
>> On Thu, 17 Apr 2014 14:47:00 -0400, Walter Bright  
>> <newshound2 at digitalmars.com>
>> wrote:
>>
>>> On 4/17/2014 10:05 AM, Steven Schveighoffer wrote:
>>>>> Obj-C only uses ARC for a minority of the objects.
>>>> Really? Every Obj-C API I've seen uses Objective-C objects, which all  
>>>> use RC.
>>>
>>> And what about all allocated items?
>>
>> What do you mean?
>
> Can you call malloc() ?

Of course. And then I can wrap it in NSData or NSMutableData.

>>>>> A UI is a good use case for ARC. A UI doesn't require high  
>>>>> performance.
>>>> I've written video processing/players on iOS, they all use blocks and  
>>>> reference
>>>> counting, including to do date/time processing per frame. All while  
>>>> using RC
>>>> network buffers. And it works quite smoothly.
>>>
>>> And did you use ref counting for all allocations and all pointers?
>>
>> Yes.
>
> You never used malloc? for anything? or stack allocated anything? or had  
> any pointers to anything that weren't ref counted?
>
> How did that work for printf?

I didn't exactly use printf, iOS has no console. NSLog logs to the xcode  
console, and that works great.

But we used FILE * plenty. And I've had no problems.

>>> There's no doubt that ref counting can be used successfully here and  
>>> there,
>>> with a competent programmer knowing when he can just convert it to a  
>>> raw
>>> pointer and use that.
>>
>> The compiler treats pointers to NSObject-derived differently than  
>> pointers to
>> structs and raw bytes.
>
> So there *are* regular pointers.

Of course, all C code is valid Objective-C code.

>> There is no need to know, you just use them like normal
>> pointers, and the compiler inserts the retain/release calls for you.
>
> I know that with ARC the compiler inserts the code for you. That doesn't  
> make it costless.

I'm not saying it's costless. I'm saying the cost is something I didn't  
notice performance-wise.

But my point is, pointers are pointers. I use them the same whether they  
are ARC pointers or normal pointers (they are even declared the same way),  
but the compiler treats them differently.

>>> And remember that if you have exceptions, then all the dec code needs  
>>> to be in
>>> exception unwind handlers.
>>
>> I haven't really used exceptions, but they automatically handle the  
>> reference
>> counting.
>
> I know it's done automatically. But you might be horrified at what the  
> generated code looks like.
>

Perhaps a reason to avoid exceptions :) I generally do anyway, even in D.

-Steve


More information about the Digitalmars-d mailing list