Article View: comp.lang.c.moderated
Article #2420Re: Efficiency Question : bits vs. bytes (or anything else, for that matter)
From: Jos A. Horsmeier
Date: Thu, 28 Mar 1996 00:00
Date: Thu, 28 Mar 1996 00:00
47 lines
2051 bytes
2051 bytes
In article <4jbciv$2kk@solutions.solon.com>, vjarnot@mnw.net wrote:
|I have set up an array in the following manner (obviously I just need
|0 or 1) :
|typedef struct my_bits {
| unsigned the_bit : 1;
|};
|
|my_bits the_array[800][800];
|
| My question is this : I have read that some operations ( =,+,- are
|what I use) are slower when performed on bits as opposed to other
|types. My objective is to optimize the code for speed, and I figured
|using less memory would help me do so, now I'm having doubts. So what
|is more efficient, bits or some other type???
I think the idea of 'bit-fields' have mislead you. The size of the matrix
above is at least 800*800 chars, not 800*800 bits as you might have thought.
This is what the Standard has to say about bit fields:
6.5.2.1. Structure and union specifiers
Constraints
An implementation may allocate any addressable storage unit large enough
to hold a bit-field. If enough space remains, a bit-field that immediately
follows another bit-field in a structure shall be packed into adjacent
bits of the same unit.
[ end of quote ]
The smalles addressable storage unit is a char and an implementation
is not required to pack adjacent structures in an addressable storage
unit, so you might a well have written:
char the_array[800][800];
because that's the cheapest you can get here without explicit (expensive)
bit fiddling implemented by yourself ...
kind regards,
Jos aka jos@and.nl
--
Atnwgqkrl gy zit vgksr, ug qshiqwtzoeqs!
Technical Details
Message-ID:
<4jckqu$a6j@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4jbciv$2kk@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: jos@and.nl (Jos A. Horsmeier) Newsgroups: comp.lang.c.moderated Subject: Re: Efficiency Question : bits vs. bytes (or anything else, for that matter) Date: 27 Mar 1996 18:00:30 -0600 Organization: AND Operations Research B.V. Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4jckqu$a6j@solutions.solon.com> References: <4jbciv$2kk@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com X-Newsreader: WinVN 0.99.5