Are packed structs slower AND safe?

Oct 26, 2021 1 Replies

In one of my projects that run on a Cortex-M0+ MCU, I have a few arrays of structs. Now I need to increase the size of the arrays, but I'm out of RAM, so I'm searching for ways to save some space in RAM.



One simple way is to pack the structs, for example with



__attribute__((packed))



in gcc. I can save some padding bytes (that waste some memory) for each element of the array, so the total amount of saved space could be enough.



I know the use of a packed struct forces the compiler to generate a slower code, because of misaligned accesses of its members. However, besides having a slower code, is the result correct in any case?


Post the structure with the variable names changed to Greek gods. Add comments to each line with the range of values stored in each variable.

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required