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

  • SEARCH
  • Home
  • 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 503995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:27:04+00:00 2026-05-13T06:27:04+00:00

I have a structure I would like to optimize the footprint of. typedef struct

  • 0

I have a structure I would like to optimize the footprint of.

typedef struct dbentry_s {
   struct dbentry_s* t_next;
   struct dbentry_s* a_next;
   char *t;
   char *a;
   unsigned char feild_m;
   unsigned char feild_s;
   unsigned char feild_other;
} dbentry;

As I understand it, the compiler creates structures in memory as you define them.
So larger types should be declared first so the small types can fill in the alignment holes.

I have read the WikiPedia article on data structure alignment and other articles on the issue.
http://en.wikipedia.org/wiki/Data_structure_alignment

But I’m still not sure, is my current ordering the most optimal or am I missing something?

Note: My compiler doesn’t support “#pragma pack”

  • 1 1 Answer
  • 1 View
  • 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-13T06:27:04+00:00Added an answer on May 13, 2026 at 6:27 am

    No, that should be the most optimal order based on common compiler behavior (keeping in mind that the standard does not actually mandate how the structures are packed with respect to the spaces between the elements, although it does guarantee the order is as specified: see ‘6.2.5 Types’ of the latest draft C1x-n1425).

    You have all your pointers up the front and all your characters down the back, so you’ll probably find that, with a four-byte pointer size you’ll end up with a 19- or 20-byte structure.

    You can easily check this by inserting the following lines in your code:

    printf ("Size of dbentry* is %d\n", sizeof (struct dbentry_s*));
    printf ("Size of char*    is %d\n", sizeof (char*));
    printf ("Size of uns char is %d\n", sizeof (unsigned char));
    printf ("Size of stucture is %d\n", sizeof (dbentry));
    

    The reason I’ve put in all the sizeof checks is to ensure you have full information. I’m well aware the sizeof(char) is always 1.

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

Sidebar

Related Questions

I have folder structure and I would like to create JSON objects based on
I have this table structure and would like to map it using Fluent Hibernate
i would like create a array of structure which have a dynamic array :
I have links in the following structure and I would like to know what
I have objects in a tree structure, I would like to aggregate status information
I have a WS Witch return to me a JSON structure. I would like
I have a structure like this struct structure { BaseObject &A; //BaseObject has a
I would like to have a structure like this: Mapping class int ID {get;set;}
I have a folder structure that I would like to have in my bundle.
I have a structure that has an array of pointers. I would like to

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.