B
bwaichu
To avoid padding in structures, where is the best place to put size_t
variables?
According the faq question 2.12 (http://c-faq.com/struct/padding.html),
it says:
"If you're worried about wasted space, you can minimize the effects of
padding by ordering the members of a structure based on their base
types, from largest to smallest."
So if I have the following:
typedef struct _Buffer_t {
char *buffer;
size_t size;
} Buffer_t;
I should have mimized padding since size_t is an unsigned long.
However, will size_t ever become an unsigned long long? If it does,
then size_t still wouldn't be larger than a pointer on the system,
right? But where should I put size_t in relation to other integer
declarations? Should I all ways assume size_t is an unsigned long when
building structures?
Now, if I made another structure:
typedef struct _Buffer2_t {
Buffer_t name;
char *buffer;
size_t size;
} Buffer2_t;
Is the above still the correct sequence to minimize padding?
Thanks.
variables?
According the faq question 2.12 (http://c-faq.com/struct/padding.html),
it says:
"If you're worried about wasted space, you can minimize the effects of
padding by ordering the members of a structure based on their base
types, from largest to smallest."
So if I have the following:
typedef struct _Buffer_t {
char *buffer;
size_t size;
} Buffer_t;
I should have mimized padding since size_t is an unsigned long.
However, will size_t ever become an unsigned long long? If it does,
then size_t still wouldn't be larger than a pointer on the system,
right? But where should I put size_t in relation to other integer
declarations? Should I all ways assume size_t is an unsigned long when
building structures?
Now, if I made another structure:
typedef struct _Buffer2_t {
Buffer_t name;
char *buffer;
size_t size;
} Buffer2_t;
Is the above still the correct sequence to minimize padding?
Thanks.