Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S269148AbTGJJtk (ORCPT ); Thu, 10 Jul 2003 05:49:40 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S269154AbTGJJtk (ORCPT ); Thu, 10 Jul 2003 05:49:40 -0400 Received: from web11801.mail.yahoo.com ([216.136.172.155]:35868 "HELO web11801.mail.yahoo.com") by vger.kernel.org with SMTP id S269148AbTGJJti (ORCPT ); Thu, 10 Jul 2003 05:49:38 -0400 Message-ID: <20030710100417.83333.qmail@web11801.mail.yahoo.com> Date: Thu, 10 Jul 2003 12:04:17 +0200 (CEST) From: =?iso-8859-1?q?Etienne=20Lorrain?= Subject: memset (was: Redundant memset in AIO read_events) To: linux-kernel@vger.kernel.org MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1356 Lines: 47 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/