Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6145887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:51:47+00:00 2026-05-23T18:51:47+00:00

I’d like to count/sum up the overhead in an object file due to packing

  • 0

I’d like to count/sum up the overhead in an object file due to packing (and, ideally, have gcc minimize it for me).

For example, consider the following structure (32 bit x86, gcc):

struct a { 
    uint8_t a_char;
    uint32_t an_integer
    uint8_t another_letter;
};

While the actual data only takes up 6 bytes, the structure takes up 12 bytes in memory because both chars are followed by 3 padding bytes. By reordering the structure as follows:

struct b { 
    uint32_t an_integer
    uint8_t a_char;
    uint8_t another_letter;
};

The structure will only have sizeof(struct b) == 8 (still 4 bytes of overhead).

(1) Ideally, I’d like for gcc to rearrange struct a to struct b and save me the space, but my version (4.2) doesn’t seem to do this for any optimization level.

(2) Alternatively, given struct a, I’d like to (automatically) get either the number 6 (total amount of overhead) or 4 (minimal amount of overhead, if members are ordered “ideally”). The purpose of this is to determine whether or not manually reordering structures is worth the time (likely not).

Is there a way for gcc to do (1), and is there a tool that would perform (2)? The closest thing I can think of for (1) is #pragma pack(1), but (I’m guessing) it would have serious performance implications by making most/all memory accesses unaligned. For (2), I’m thinking a Perl script parsing debugging symbols might be able to do this, but I’m not familiar enough with DWARF to know for sure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:51:47+00:00Added an answer on May 23, 2026 at 6:51 pm

    For #1, the reason it’s not done is that both the C and C++ standards prohibit structure member reordering.

    Yes, struct packing will generally reduce performance. And, as mentioned in a comment, in some cases on non-x86 architectures you can get a SIGBUS if you try to operate on a member.

    For #2, yes a perl script might be able to do it. Instead of parsing DWARF info, you could try scanning the source code for struct definitions, and maybe generate some small test programs to check the sizeof() of structs and members and so on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I would like to count the length of a string with PHP. The string
I have just tried to save a simple *.rtf file with some websites and
I am trying to render a haml file in a javascript response like so:
i got an object with contents of html markup in it, for example: string
I have a reasonable size flat file database of text documents mostly saved in
I have some data like this: 1 2 3 4 5 9 2 6
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.