From: Tom Tromey <tromey@redhat.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Optimizing memory footprint of bidi code
Date: Mon, 07 Jun 2010 09:14:36 -0600 [thread overview]
Message-ID: <m3ljaqoowz.fsf@fleche.redhat.com> (raw)
In-Reply-To: <E1OLdLs-0006ZF-Dw@fencepost.gnu.org> (Eli Zaretskii's message of "Mon, 07 Jun 2010 10:30:56 -0400")
>>>>> "Eli" == Eli Zaretskii <eliz@gnu.org> 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
next prev parent reply other threads:[~2010-06-07 15:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-07 14:30 Optimizing memory footprint of bidi code Eli Zaretskii
2010-06-07 15:14 ` Tom Tromey [this message]
2010-06-07 15:46 ` Andreas Schwab
2010-06-07 16:01 ` Stefan Monnier
2010-06-07 23:10 ` Eli Zaretskii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3ljaqoowz.fsf@fleche.redhat.com \
--to=tromey@redhat.com \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.