• Skip to primary navigation
  • Skip to main content
FDI: Future Designs, Inc.

FDI

Future Designs, Inc.

  • Products
    • μEZ GUI
    • ELI
    • ΣyG
    • Modular Development Kits – DK
    • Other Products
    • End of Life
    • All Products (By part number)
  • Engineering Design
  • Production
  • Support
    • Forums
  • About FDI
    • News
    • Management
    • Partners
    • Distributors
    • Practices
    • Careers
    • New Customer Referral
  • Contact Us
  • Show Search
Hide Search

Manually optimize structures

Homepage › Forums › μEZ › Software › Manually optimize structures

  • This topic has 0 replies, 1 voice, and was last updated 4 months, 1 week ago by Logan Moon.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • February 6, 2025 at 10:22 pm #16819
    Logan Moon
    Keymaster

      (This message was transferred over from our old forum)
      Posted August 19, 2015
      By Todd DeBoer
      [hr]
      On 10/30/2009 wella asked, “I think that the compiler could not optimise the structure arrangement.
      If you do it manualy, you can save some space.
      Below are two identical structs but the second one has all 8bits items at the end.

      uint32_t s0 = sizeof(I2C_Request0);
      uint32_t s1 = sizeof(I2C_Request1);

      This example was compiled by gcc version 4.4.1 (Sourcery G++ 4.4-180) and the
      s0 = 32, s1 = 24,

      8 byte save is quite interresting.

      typedef struct {
      TUInt8 iAddr; // 7-bit address of I2C device
      TUInt16 iSpeed; // in kHz
      TUInt8 *iWriteData; // 0 or NULL value means no write action
      TUInt8 iWriteLength; //————> ??????
      TUInt32 iWriteTimeout;
      TUInt8 *iReadData; // 0 or NULL value means no read action
      TUInt8 iReadLength;//————> ??????
      TUInt32 iReadTimeout;
      volatile T_uEZI2CStatus iStatus;
      } I2C_Request;

      typedef struct {
      TUInt8 *iWriteData; // 0 or NULL value means no write action
      TUInt32 iWriteTimeout;
      TUInt8 *iReadData; // 0 or NULL value means no read action
      TUInt32 iReadTimeout;
      volatile T_uEZI2CStatus iStatus;
      TUInt16 iSpeed; // in kHz
      TUInt8 iWriteLength;
      TUInt8 iReadLength;
      TUInt8 iAddr; // 7-bit address of I2C device
      } I2C_Request1;”
      [hr]
      (Follow up post)

      Answered:

      Right. Many compilers won’t rearrange the entries in a structure and will only pad each individual entry for alignment, but they will combine them based on order (8-bit back to back will be combined). Given our previous converstation about making these TUInt8’s larger, this will nullify the setup. But you are correct, we probably should consider this when first building the structures.

    • Author
      Posts
    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.
    Log In

    Partners

    NXP
    Renesas

    ARM
    SEGGER

    STMicroelectronics
    SAFERTOS

    FreeRTOS

    Copyright © 2025 Future Designs, Inc. | μEZ GUI | ELI | Engineering Design | Production | Privacy Policy | Log in