lkml.org 
[lkml]   [2005]   [Sep]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: p = kmalloc(sizeof(*p), )
On Sun, Sep 18, 2005 at 10:31:36AM -0700, Linus Torvalds wrote:
>
>
> On Sun, 18 Sep 2005, Al Viro wrote:
> >
> > That's why you do
> > *p = (struct foo){....};
> > instead of
> > memset(p, 0, sizeof...);
> > p->... =...;
>
> Actually, some day that migth be a good idea, but at least historically,
> gcc has really really messed that kind of code up.
>
> Last I looked, depending on what the initializer was, gcc would create a
> temporary struct on the stack first, and then do a "memcpy()" of the
> result. Not only does that obviously generate a lot of extra code, it also
> blows your kernel stack to kingdom come.

Ewwwww... I'd say that it qualifies as one hell of a bug (and yes, at least
3.3 and 4.0.1 are still doing that). What a mess...

> (For _small_ structures it's wonderful. As far as I can tell, gcc does a
> pretty good job on structs that are just a single long-word in size).
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-09-18 19:48    [W:0.169 / U:0.040 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site