Cleaned up C++

John Colvin via Digitalmars-d digitalmars-d at puremagic.com
Fri Apr 24 00:23:06 PDT 2015


On Friday, 24 April 2015 at 01:54:11 UTC, Walter Bright wrote:
> On 4/23/2015 3:11 PM, deadalnix wrote:
>> For arbitrary large, you can always do something like :
>>
>> Item* itemPtr = (arbitrarylarge < thresold)
>>   ? alloca(arbitrarylarge)
>>   : GC.alloc(arbitrarylarge);
>>
>> One extra check compared to a heap allocation is not going to 
>> make things
>> terrible, and it is likely to be very predictible anyway (most 
>> arbitrarylarge
>> size are actually small in practice).
>
> You can, but it just doesn't pay off. Even if you found a case 
> that did, it doesn't mean it pays off in general, and so would 
> be poor advice.
>
> BTW, since alloca() doesn't survive function scope, might as 
> well use malloc/free instead of the GC. Or do like I've done 
> and have an array of preallocated larger buffers.
>
> I.e. if you've gotten to tuning code at this level, the 
> compiler picking things automatically for you is unlikely to be 
> helpful. Hence my not being convinced by bearophile's 
> assessment.

Except of course that alloca is a lot cheaper than malloc/free.


More information about the Digitalmars-d mailing list