🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c.moderated
Article #2412

Re: Efficiency Question : bits vs. bytes (or anything else, for that matter)

#2412
From: Herbert Kremser
Date: Wed, 27 Mar 1996 23:58
38 lines
1930 bytes
Asmodeus (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;
: };

lets say that obvious bug here was just a typo.

: 
: 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???


Who makes you think the compiler will use less memory for my_bits
the_array[800][800]; compared to for instance char the_array[800][800];
The compiler may do so, but i guess most don't.

In fact i just tried it here, and the result was that your version
used 4 times as much memory as the char version. (The compiler uses
4 bytes (his int) for my_bits.

But if you want to optimize for speed, there is no general solution,
you should check how your compiler handles bitfields and can decide then
if it makes sense or not.

Herbert
-- 
Herbert Kremser                                      |  "On the Internet,
kremser@flinux.tu-graz.ac.at                         |   nobody knows
kremser@sbox.tu-graz.ac.at                           |   you're a dog." 
Technical Details
Message-ID: <4jckne$a0l@solutions.solon.com>
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
References: <4jbciv$2kk@solutions.solon.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail
From: kremser@sbox.tu-graz.ac.at (Herbert Kremser)
Newsgroups: comp.lang.c.moderated
Subject: Re: Efficiency Question : bits vs. bytes (or anything else, for that matter)
Date: 27 Mar 1996 17:58:38 -0600
Organization: Graz University of Technology, Austria
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4jckne$a0l@solutions.solon.com>
References: <4jbciv$2kk@solutions.solon.com>
NNTP-Posting-Host: solutions.solon.com
X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]