This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Use malloca instead alloca


On Sat, Jan 12, 2013 at 02:38:57PM -0800, Paul Eggert wrote:
> On 01/12/2013 02:24 PM, Rich Felker wrote:
> >> gcc does not optimize alloca
> >> > well so type[constant] is faster than alloca(constant). This is bug in
> >> > gcc and can be fixed.
> > No, this _cannot_ be fixed. If any non-static-sized objects
> 
> Surely GCC can be fixed so that a function that does this first:
> 
>    char *p = alloca (100);
> 
> is executed with code that's no slower than if the function had
> done this first:
> 
>    char buf[100];
>    char *p = buf;
> 
> Currently, GCC doesn't do this optimization, but I don't see any
> reason why it couldn't.

We're not talking about this situation. We're talking about things of
the form:

T foo(size_t n)
{
    char *p;
    if (n<K) p = alloca(n);
    else p = malloc(n);
    /* ... */
}

This is FUNDAMENTALLY more expensive than:

T foo(size_t n)
{
    char *p, buf[K];
    if (n<K) p = buf;
    else p = malloc(n);
    /* ... */
}

How is that hard to understand?

Rich


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]