🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#2416
From: Lawrence Kirby
Date: Wed, 27 Mar 1996 23:59
40 lines
1883 bytes
In article <4jbciv$2kk@solutions.solon.com> 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;
>};

I assume you meant:

typedef struct {
        unsigned the_bit : 1;
} my_bits;

The first problem here is that the struct does *not* consist of just one bit.
The smallest size it can have is 1 byte (char) and it could well be more
depending on how your compiler allocates bitfields.

>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.

On most archetectures, yes.

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

Unless you ave platform specific information to the contrary you should
assume that int/unsigned int are the most efficient integer types.

-- 
-----------------------------------------
Lawrence Kirby | fred@genesis.demon.co.uk
Wilts, England | 70734.126@compuserve.com
-----------------------------------------
Technical Details
Message-ID: <4jckp6$a3i@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: Lawrence Kirby <fred@genesis.demon.co.uk>
Newsgroups: comp.lang.c.moderated
Subject: Re: Efficiency Question : bits vs. bytes (or anything else, for that matter)
Date: 27 Mar 1996 17:59:34 -0600
Organization: none
Sender: clc@solutions.solon.com
Approved: clc@solutions.solon.com
Message-ID: <4jckp6$a3i@solutions.solon.com>
References: <4jbciv$2kk@solutions.solon.com>
Reply-To: fred@genesis.demon.co.uk
NNTP-Posting-Host: solutions.solon.com
X-NNTP-Posting-Host: genesis.demon.co.uk
X-Newsreader: Demon Internet Simple News v1.27
X-Mail2News-Path: genesis.demon.co.uk