nholthaus / units

a compile-time, header-only, dimensional analysis and unit conversion library built on c++14 with no dependencies.

Home Page:http://nholthaus.github.io/units/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Empty base class optimization for MSVC

andipeer opened this issue · comments

Please include the following information in your issue:

  1. Which version of units you are using
    3.0.0 Beta 2

  2. Which compiler exhibited the problem (including compiler version)
    MSVC

Problem description

In contrast to most other compilers, MSVC does not enable empty base class optimization by default. This means that when using units on MSVC, although most method calls will be optimized away, there will be a memory overhead of at least 1 byte compared to just using plain floating point types.

Solution

As a solution, in our code base we added the empty_bases attribute to the units::unit class in case it is compiled on MSVC. This indeed removes the memory overhead.

If you approve that this should be addressed, I can create a pull request with the required changes.