From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tom Tromey Newsgroups: gmane.emacs.devel Subject: Re: Optimizing memory footprint of bidi code Date: Mon, 07 Jun 2010 09:14:36 -0600 Message-ID: References: Reply-To: Tom Tromey NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1275924577 20086 80.91.229.12 (7 Jun 2010 15:29:37 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 7 Jun 2010 15:29:37 +0000 (UTC) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jun 07 17:29:36 2010 connect(): No such file or directory Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1OLeGd-0003kt-AR for ged-emacs-devel@m.gmane.org; Mon, 07 Jun 2010 17:29:35 +0200 Original-Received: from localhost ([127.0.0.1]:50877 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLeGc-0003fd-93 for ged-emacs-devel@m.gmane.org; Mon, 07 Jun 2010 11:29:34 -0400 Original-Received: from [140.186.70.92] (port=58490 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OLe2E-00018M-7l for emacs-devel@gnu.org; Mon, 07 Jun 2010 11:14:43 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OLe2C-0002UJ-9T for emacs-devel@gnu.org; Mon, 07 Jun 2010 11:14:41 -0400 Original-Received: from mx1.redhat.com ([209.132.183.28]:53980) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OLe2C-0002U3-2q; Mon, 07 Jun 2010 11:14:40 -0400 Original-Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o57FEcF4021775 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 7 Jun 2010 11:14:38 -0400 Original-Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o57FEbfr016335; Mon, 7 Jun 2010 11:14:38 -0400 Original-Received: from opsy.redhat.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id o57FEbSd032026; Mon, 7 Jun 2010 11:14:37 -0400 Original-Received: by opsy.redhat.com (Postfix, from userid 500) id C4AAF50802E; Mon, 7 Jun 2010 09:14:36 -0600 (MDT) X-Attribution: Tom In-Reply-To: (Eli Zaretskii's message of "Mon, 07 Jun 2010 10:30:56 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:125582 Archived-At: >>>>> "Eli" == Eli Zaretskii writes: Eli> I see a bidi_dir_t enumeration that has only 3 possible values. Can Eli> we trust modern compilers to use the smallest integer type for Eli> enumerations? If so, this part is already taken care of. If not, how Eli> to make this type smaller without losing the benefits of an enumerated Eli> type (I don't want to manipulate magic values or macros)? In C an enum is always an int. In a struct the compiler will not automatically shrink this to a bitfield. However, you can declare it as a bitfield. GCC will check to make sure that all the enumeration values fit in the bitfield, so you will get an error if you add a constant to the enum causing it to no longer fit. Bitfield enums are not portable. So, gcc and gdb do this: #if defined(__GNUC__) && (__GNUC__ >= 2) #define ENUM_BITFIELD(TYPE) enum TYPE #else #define ENUM_BITFIELD(TYPE) unsigned int #endif Then in the definition: struct main_type { ... ENUM_BITFIELD(type_code) code : 8; ... }; I think this approach results in a good tradeoff of type safety, size, and portability, as long as a significant fraction of developers are using GCC. Eli> Maybe manipulating bitfields is no longer an issue with current Eli> architectures and compiler technology. It increases code size, which can matter. The only way to know for sure is to try it and profile. I can't answer the rest of your questions. Tom