Article View: comp.lang.c.moderated
Article #2425Re: Efficiency Question : bits vs. bytes (or anything else, for that matter)
From: Konrad Schwarz
Date: Thu, 28 Mar 1996 12:47
Date: Thu, 28 Mar 1996 12:47
29 lines
1529 bytes
1529 bytes
I posted the following suggestion for a ``packed array'' of bits yesterday:
|> If you are interested in space, one suggestion is
|>
|> # include <limits.h>
|>
|> # define UNSIGNED_BIT (CHAR_BIT * sizeof (unsigned))
|>
|> struct {
|> unsigned the_bits [UNSIGNED_BIT]: 1;
|> } the_array [800][(800 + UNSIGNED_BIT - 1) / UNSIGNED_BIT];
|>
|> # define BIT(X, Y)\
|> the_array [Y][(X) / UNSIGNED_BIT].the_bits [(X) % UNSIGNED_BIT]
Upon further reflection, I now am more inclined toward the following:
struct {
unsigned b [800][800]:1;
} the_array;
Furthermore, in yesterdays posting making the size of the cell sizeof (unsigned)
is arbitrary; in particular, it has nothing to do with the fact that the
type of the bitfield is unsigned. In the environment I am currently
computing in, a cell size of sizeof (void *) would be more likely to make
the cell size equal to the machine word length. I doubt that either choice
will make much of a difference speed wise.
Konrad Schwarz
Technical Details
Message-ID:
<4je1p1$g1s@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4jbciv$2kk@solutions.solon.com> <4jckmc$9v7@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: schwarz@mips.complang.tuwien.ac.at (Konrad Schwarz) Newsgroups: comp.lang.c.moderated Subject: Re: Efficiency Question : bits vs. bytes (or anything else, for that matter) Date: 28 Mar 1996 06:47:29 -0600 Organization: TU Wien Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4je1p1$g1s@solutions.solon.com> References: <4jbciv$2kk@solutions.solon.com> <4jckmc$9v7@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com