The Dark Side of C++ - Empty Base Optimization

Поділитися
Вставка
  • Опубліковано 3 лис 2024

КОМЕНТАРІ • 9

  • @tigrux
    @tigrux Рік тому +5

    You are a dark wizard in C++ arts!

    • @ZenSepiol
      @ZenSepiol  Рік тому +1

      Thanks! Hope it was helpful!

  • @tourdesource
    @tourdesource Рік тому +1

    Super clear explanation, thanks Zen.

  • @namanbarna394
    @namanbarna394 5 місяців тому

    In C++ the base optimization struct is known as std::_Compressed_pair

  • @toggle-tap2196
    @toggle-tap2196 Рік тому +1

    W vid keep up the work

  • @alexandresendra
    @alexandresendra Рік тому +2

    So if you have Alloc as a member of your class it would add 1 byte to your list class ?

    • @ZenSepiol
      @ZenSepiol  Рік тому +3

      Yes, it has to. The standard says you need to be able to take the address of the Alloc object. Thus it needs to occupy space.

    • @simonmaracine4721
      @simonmaracine4721 5 місяців тому

      It could occupy much more space depending on the other member variables, due to alignment requirements. So it most likely occupies 8 bytes, and less likely 4 or 2 or 1.