[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: using sizeof



On 5/14/07, J HU <judowold@hotmail.com> wrote:
Dear all,

Perhaps it's an easy/silly question but I don't understand how it works.

(I'm working in a debian)
I have declared a structure and I'm using the "sizeof" to get the size of
this structure.

After the call I get that the total size is 64Bytes but if I get the size of
each field and I add them manually I get that it should be 61Bytes...

Anyone knows why the result is not the same?

I noticed you got an answer. This page can help also:

http://en.wikipedia.org/wiki/Data_structure_alignment

The effects of alignment in performance (and even stability, if you're
writing low level code) depend on the architecture.

For instance: A memory access can be much faster on
some architectures if the base address for the request
is aligned.

So, if you can afford the padding space in memory, also remember that
you have to be careful with pointer arithmetic. You should not assume that:

 *((char*)(pointer + sizeof(mystruct)  - 1))

Is the last byte of your structure.

Regards,
Nelson.-

--
http://arhuaco.org
http://emQbit.com



Reply to: