ESP32-S3 and 32 Bit data alignment

greg-dickson
Posts: 24
Joined: Sun Nov 01, 2020 1:51 am

ESP32-S3 and 32 Bit data alignment

Postby greg-dickson » Thu Sep 14, 2023 11:54 am

Could someone please enlighten me.

Does the ESP32-S3 and other ESP32 chips align data on 32bit words.

In other words.

Does a unint32_t and a uint8_t take the same amount of memory space?

Thank you.

MicroController
Posts: 1736
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP32-S3 and 32 Bit data alignment

Postby MicroController » Thu Sep 14, 2023 12:46 pm

No, the chips don't align any data. The compiler does.
The flash and DRAM are byte-addressable/-accessible in hardware, hence gcc (usually) does 1-byte alignment on 8-bit values.
You can check the value of sizeof(uint8_t) or sizeof(uint32_t) yourself.
However,

Code: Select all

struct {
  uint8_t u8;
  uint32_t u32;
} x;
will occupy 8 bytes due to gcc's (on ESPs mostly unnecessary) padding/alignment of the uint32_t.

greg-dickson
Posts: 24
Joined: Sun Nov 01, 2020 1:51 am

Re: ESP32-S3 and 32 Bit data alignment

Postby greg-dickson » Thu Sep 14, 2023 2:07 pm

MicroController wrote:
Thu Sep 14, 2023 12:46 pm
No, the chips don't align any data. The compiler does.
The flash and DRAM are byte-addressable/-accessible in hardware, hence gcc (usually) does 1-byte alignment on 8-bit values.
You can check the value of sizeof(uint8_t) or sizeof(uint32_t) yourself.
However,

Code: Select all

struct {
  uint8_t u8;
  uint32_t u32;
} x;
will occupy 8 bytes due to gcc's (on ESPs mostly unnecessary) padding/alignment of the uint32_t.
Thanks I did check another way by adding an array to some code and checking the upload size and it did follow your explanation.
Thank you I couldn't find any specific information elsewhere.

Who is online

Users browsing this forum: Baldhead and 108 guests