Article View: comp.lang.c.moderated
Article #2411Re: Efficiency Question : bits vs. bytes (or anything else, for that matter)
From: Kurt Watzka
Date: Wed, 27 Mar 1996 23:58
Date: Wed, 27 Mar 1996 23:58
39 lines
1914 bytes
1914 bytes
vjarnot@mnw.net (Asmodeus) writes:
>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];
You are still allowed to take the address of "the_array[42][471]".
If the smallest addressable unit on your machine is not one bit,
I'd expect _every_ compiler to generate objects that are at least
the size of the smallest addressable unit. It might well decide
to use at least the size of an int (the "natural object size" on
your machine) for each "struct my_bits".
> 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???
This depends on the capacities of your machine, not on the
programming language you use. If your machine allows unaligned
access to memory, it is still possible that unaligned access
is _much_ slower than natural access.
In general, speed efficiency and size efficiency are incompatible
goals, and there is a trade-off between them.
Kurt
--
| Kurt Watzka Phone : +49-89-2180-6254
| watzka@stat.uni-muenchen.de
| ua302aa@sunmail.lrz-muenchen.de
Technical Details
Message-ID:
<4jckn0$a01@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: watzka@stat.uni-muenchen.de (Kurt Watzka) Newsgroups: comp.lang.c.moderated Subject: Re: Efficiency Question : bits vs. bytes (or anything else, for that matter) Date: 27 Mar 1996 17:58:24 -0600 Organization: Leibniz-Rechenzentrum, Muenchen (Germany) Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4jckn0$a01@solutions.solon.com> References: <4jbciv$2kk@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com