[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: on the use of char
From:       Thiago Macieira <thiago.macieira () kdemail ! net>
Date:       2004-07-29 2:34:36
Message-ID: 200407282334.44788.thiago.macieira () kdemail ! net
[Download RAW message or body]


George Staikos wrote:
>   So if your goal is to store a relatively small number and not waste
> space, can I recommend either using a bitfield int, or thinking again
> "is it really worth the possible bugs in order to save 3 bytes out
> of, ex., ~5MB"?

Let me also point out that it would only make sense to use char (or 
signed char or unsigned char) in a struct, and only when you're careful 
about padding.

Using 'char' on the stack or on heap won't help you because variables 
will be 4-byte aligned (or more) anyways. So you get 4 bytes allocated 
despite the fact that you're using 'char'.

If you write a struct like this:
	struct {
		char small;
		int large;
		int large2;
	};

then the struct is also 12 bytes in size and you're gaining NO space by 
using char, at all.

-- 
  Thiago Macieira  -  Registered Linux user #65028
   thiago (AT) macieira (DOT) info
    ICQ UIN: 1967141   PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

[Attachment #3 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic