From: James Stevenson <james@stev.org>
To: Massimiliano Cialdi <cialdi@firenze.net>
Cc: linux-c-programming <linux-c-programming@vger.kernel.org>,
wwp <subscript@free.fr>
Subject: Re: bitfield array
Date: Tue, 13 Jan 2004 01:02:19 +0000 (GMT) [thread overview]
Message-ID: <Pine.LNX.4.44.0401130054200.1358-100000@jlap.stev.org> (raw)
In-Reply-To: <20040112115643.0000382e.cialdi@firenze.net>
> > IOW, if you use a 1-bit bitfield, it will still be require an amount
> > of memory counted in bytes. That's partly why bitfields are not so
> > used for optimization, 'cause following the compiler you don't gaim
> > memory space not cpu time.
> I work with a (very) limited memory embedded system. I need to save
> memory, no matter in cpu time.
if this is the case you could create a macro / function to access
the individtual bits.
It is slow but you dont have a problem with that
something like
int grab_bit(u8 *bits, int bit) {
return ((bits[bit >> 3] & (1 << (bit >> 3) & 255)) >> bit);
}
void set_bit(u8 *bits, int bit) {
bits[bit >> 3] |= 1 << ((bit >> 3) & 255);
}
I am pritty sure the above is wrong but you should get the rought idea
you have an array of 8bits and you access by dividing by 8 then using the
reminder value as the mask to access the individtual bits.
It should be possible todo it with shifts so you dont loose soo much
speed. Then just use the functions with a declared array of bits.
James
next prev parent reply other threads:[~2004-01-13 1:02 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-12 10:10 bitfield array Massimiliano Cialdi
2004-01-12 10:29 ` wwp
2004-01-12 10:56 ` Massimiliano Cialdi
2004-01-12 13:40 ` Mariano Moreyra
2004-01-13 1:02 ` James Stevenson [this message]
2004-01-12 21:06 ` Glynn Clements
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=Pine.LNX.4.44.0401130054200.1358-100000@jlap.stev.org \
--to=james@stev.org \
--cc=cialdi@firenze.net \
--cc=linux-c-programming@vger.kernel.org \
--cc=subscript@free.fr \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).