Re: why is a bool 4 bytes in g++?

Discussion in 'C++' started by Tim Partridge, Jul 18, 2003.

  1. Actually, the matrix of bools I have to store is an upper triangular
    matrix. For anyone who might read this later, I found this site:

    http://www.nist.gov/dads/HTML/uppertriangm.html

    which describes the how to convert an upper triangular matrix to a 1D
    array. Entry (i,j) in the matrix corresponds to entry (2n-i)(i-1)/2 + j
    in the array, where n is the number of rows (or columns), and 1 <= i,j <= n.


    On Thu, 17 Jul 2003, Jakob Bieling wrote:

    > "Tim Partridge" <> wrote in message
    > news:p...
    > > Sorry to ask a question that I'm sure has been answered, but I had trouble
    > > finding it. Why would a bool not be 1 bit, or at most 1 byte? Is it for
    > > reasons of instruction efficiency?
    > >
    > > In g++ 2.95.2, a bool is 4 bytes and a char is 1 byte. I have to store a
    > > 90,000 entry 2D array of bools. Would it not make more sense for me to
    > > store chars instead of bools, saving me 270,000 bytes?

    >
    >
    > If you are after saving space, you should go for a vector< vector
    > <bool> >. And if you want to save even more, then just use a single vector
    > <bool> and calculate the 2D offsets yourself (not too difficult). Actually,
    > I would even prefer the vector <bool> over vector< vector <bool> >.
    >
    > hth
    > --
    > jb
    >
    > (replace y with x if you want to reply by e-mail)
    >
    >
    >
     
    Tim Partridge, Jul 18, 2003
    #1
    1. Advertising

  2. On Fri, 18 Jul 2003, Tim Partridge wrote:

    *snip*
    > which describes the how to convert an upper triangular matrix to a 1D
    > array. Entry (i,j) in the matrix corresponds to entry (2n-i)(i-1)/2 + j
    > in the array, where n is the number of rows (or columns), and 1 <= i,j <= n.

    *snip*


    Note the additional restriction of i >= j.
     
    Tim Partridge, Jul 21, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roel Schroeven

    Re: why is a bool 4 bytes in g++?

    Roel Schroeven, Jul 17, 2003, in forum: C++
    Replies:
    4
    Views:
    4,595
    David Hall
    Jul 18, 2003
  2. E. Robert Tisdale

    Re: why is a bool 4 bytes in g++?

    E. Robert Tisdale, Jul 17, 2003, in forum: C++
    Replies:
    0
    Views:
    420
    E. Robert Tisdale
    Jul 17, 2003
  3. Evan
    Replies:
    4
    Views:
    480
    Herb Sutter
    Aug 5, 2003
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,215
    Smokey Grindel
    Dec 2, 2006
  5. Yandos
    Replies:
    12
    Views:
    5,155
    Pete Becker
    Sep 15, 2005
Loading...

Share This Page