You are here:

C/structure padding

Advertisement


Question
In an interview i was asked about use of structure padding,i told processing speed gets increased,then they asked that how is it going to increase ?.
I want to know the answer for it.

thanks,
vara

Answer
What you told is correct.
But that is the byproduct.

Actually structure padding is done to do memory alignment.
As you know the size of pointer is 4 bytes.
So, if everything is organized by a multiple of 4, then it will be easier and faster to calculate the addresses and processing them.

But, this is not true always. One of the places is structures where different sized variables are clubbed.
So, if you want to make things faster, then make them align to 4 byte boundaries and for that you need padding.

-Narendra

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.