on the use of char

Thiago Macieira thiago.macieira at kdemail.net
Thu Jul 29 03:34:36 BST 2004


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20040728/30b408f8/attachment.sig>


More information about the kde-core-devel mailing list