lkml.org 
[lkml]   [2003]   [Jul]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectmemset (was: Redundant memset in AIO read_events)
 Note that using memset() is better reserved to initialise variable-size
structures or buffers. Even if memset() is extremely optimised,
it is still not as fast as not doing anything.

read_events(...) {
struct io_event ent;
memset(&ent, 0, sizeof(ent));
while (...) {
aio_read_evt(ctx, &ent);
}
...
}

Should be written (when "ent" has to be cleared):
read_events(...) {
struct io_event ent = {};
while (...) {
aio_read_evt(ctx, &ent);
}
...
}

Just compare the code generated by (using GCC):
struct io_event ent;
memset(&ent, 0, sizeof(ent));
ent.data = 0;
if (ent.obj != 0) printf ("bad");

And:
struct io_event ent = {};
ent.data = 0;
if (ent.obj != 0) printf ("bad");

and that is even without speaking of complete variable elimination
when the structure is not used, unknown pointer alignement when
memset function is not inlined, or aliasing optimisation.

Etienne.

___________________________________________________________
Do You Yahoo!? -- Une adresse @yahoo.fr gratuite et en français !
Yahoo! Mail : http://fr.mail.yahoo.com
-
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-03-22 13:46    [W:0.038 / U:0.568 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site