John Carmack applauds D's pure attribute

Peter Alexander peter.alexander.au at gmail.com
Wed Mar 7 01:09:59 PST 2012


On Wednesday, 7 March 2012 at 02:25:41 UTC, Walter Bright wrote:
> On 3/6/2012 4:27 AM, Manu wrote:
>> On 26 February 2012 00:55, Walter Bright 
>> <newshound2 at digitalmars.com
>>    Most straight up GC vs malloc/free benchmarks miss 
>> something crucial. A GC
>>    allows one to do substantially *fewer* allocations. It's a 
>> lot faster to not
>>    allocate than to allocate.
>> Do you really think that's true?
>
> Yes.

I think you're both right. GC does definitely allow you to do 
less allocations, but as Manu said it also makes people more 
allocation happy.


>> Are there any statistics to support that?
>
> No, just my experience using both.
>
> Consider strings. In C, I'd often have a function that returns 
> a string. The caller then (eventually) free's it. That means 
> the string must have been allocated by malloc.

I'd say it is bad design to return a malloc'd string. You should 
take a destination buffer as an argument and put the string there 
(like strcpy and friends). That way you can do whatever you want.

Sean made the good point that using buffers like that can lead to 
errors, but D's arrays make things a lot safer.



More information about the Digitalmars-d mailing list