Search⌘ K

Performance & Memory Considerations

Understand the memory and performance implications of using std::any in C++17. Learn about dynamic memory allocations, small buffer optimization, and how different compilers affect the size and overhead of std::any objects.

std::any looks quite powerful, and you might use it to hold variables of variable types… but you might ask what the price is for such flexibility.

The Main Issue: Extra Dynamic Memory Allocations.

std::variant and std::optional don’t require any extra memory allocations but this is because they know which type (or types) will be ...