lundi 16 août 2021

Does pack apply to nested objects and structs

While working on an ARM Cortex-M4 with gcc the following situation has arisen. To reduce the RAM footprint of the software I am looking into using pack. The following example details a class with a templated variable holing many different variables.

#pragma pack(push,4)
template<class TYPE>
class foo 
{
  public:
    // Normal functions

  private:
    TYPE bar;
    // Some other variables.

};
#pragma pack(pop)

Will the pack property work for the variables in TYPE or only on the padding around bar?

When tried this gave only a marginal improvement. I could not deduct if this was due to the posibility TYPE had no benefits from pack or only the variables in the class foo where packed.

Aucun commentaire:

Enregistrer un commentaire