[riot-commits] [RIOT-OS/RIOT] 4b8881: gnrc/netif/hdr.h: Optimized structure layout

Kaspar Schleiser kaspar at schleiser.de
Mon May 14 14:29:12 CEST 2018


  Branch: refs/heads/master
  Home:   https://github.com/RIOT-OS/RIOT
  Commit: 4b8881abb499f280f630b6a95f17170d4417c1de
      https://github.com/RIOT-OS/RIOT/commit/4b8881abb499f280f630b6a95f17170d4417c1de
  Author: Marian Buschsieweke <marian.buschsieweke at ovgu.de>
  Date:   2018-05-14 (Mon, 14 May 2018)

  Changed paths:
    M sys/include/net/gnrc/netif/hdr.h

  Log Message:
  -----------
  gnrc/netif/hdr.h: Optimized structure layout

Reordered struct members to not waste memory due to padding.

Before:
``` C
typedef struct {
    uint8_t src_l2addr_len;
    uint8_t dst_l2addr_len;
    kernel_pid_t if_pid;    // <-- 16 bit, is aligned to 16 bit
    uint8_t flags;
    uint8_t __padding_byte; // <-- Inserted to fulfill padding requirements
    int16_t rssi;           // <-- 16 bit, is NOT aligned to 16 bit
    uint8_t lqi;
    uint8_t __padding_byte2;// <-- Inserted to fulfill padding requirements
} gnrc_netif_hdr_t;
```

Now:
``` C
typedef struct {
    uint8_t src_l2addr_len;
    uint8_t dst_l2addr_len;
    kernel_pid_t if_pid;    // <-- 16 bit, is aligned to 16 bit
    uint8_t flags;
    uint8_t lqi;
    int16_t rssi;           // <-- 16 bit, is aligned to 16 bit
} gnrc_netif_hdr_t;
```

When build for the `bluepill` board, the new layout reduces the size by 2 bytes.


  Commit: d6f9be77b5f7c3c904adc8d297c9b1ee2fb9e959
      https://github.com/RIOT-OS/RIOT/commit/d6f9be77b5f7c3c904adc8d297c9b1ee2fb9e959
  Author: Kaspar Schleiser <kaspar at schleiser.de>
  Date:   2018-05-14 (Mon, 14 May 2018)

  Changed paths:
    M sys/include/net/gnrc/netif/hdr.h

  Log Message:
  -----------
  Merge pull request #9123 from maribu/pack_structs

gnrc/netif/hdr.h: Optimized structure layout


Compare: https://github.com/RIOT-OS/RIOT/compare/0b0fea9a2e8c...d6f9be77b5f7
      **NOTE:** This service been marked for deprecation: https://developer.github.com/changes/2018-04-25-github-services-deprecation/

      Functionality will be removed from GitHub.com on January 31st, 2019.


More information about the commits mailing list