Cleaned up C++

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 23 18:54:18 PDT 2015


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.


More information about the Digitalmars-d mailing list