top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

What is the use of structure padding in C?

+5 votes
289 views

What is structure padding and how it is used at processor level?

posted Nov 24, 2013 by sivanraj

Share this question
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

2 Answers

+1 vote

Padding is adding extra bits at the end, so that the structure completes the word boundary. Padding is done to do memory alignment. Using
-> #pragma ,
->__attrubute__((_packed_)) ,the strucutre padding can be avoided.
For Example:
P (Padding): (1 bit) Used to indicate if there are extra padding bytes at the end of the RTP packet. A padding might be used to fill up a block of certain size, for example as required by an encryption algorithm. The last byte of the padding contains the number of how many padding bytes were added (including itself)

answer Nov 25, 2013 by Giri Prasad
0 votes

Some architectures will perform better if only aligned accesses are made, so putting 32-bit objects on 32-bit boundaries, and 64-bit objects on 64-bit boundaries can improve the speed of your application.

Some architectures are completely incapable of making unaligned accesses, and on those architectures not padding can be a real disaster.

answer Nov 25, 2013 by Deepak Dasgupta
Similar Questions
+6 votes

Structure padding is useful for increasing processing speed for input/output, correct?
My question is i have tested structure padding on 32 and 64 bit system but both the place padding is done to achieve 4 Bytes jump, So why not 8 byte for 64 Bit system?

+4 votes

Give a good data structure for having n queues (n not fixed) in a finite memory segment. You can
have some data-structure separate for each queue. Try to use at least 90% of the memory space.

+1 vote

Given an array of 1s and 0s which has all 1s first followed by all 0s. Find the number of 0s. Count the number of zeroes in the given array.

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...