Default Capacity & Growth Rate of C++ std::vector

If you're creating a lot of small vectors in C++, you should probably consider using a small-size optimized vector instead. But, if you can't do that for some reason, you might wonder if there is any win to be had by reserve()ing a small size in advance. While the standard doesn't require vectors to have … Continue reading Default Capacity & Growth Rate of C++ std::vector

Warning: std::numeric_limits::min() > 0

Here's a baffling design choice (which I'm reliably informed C++ inherited from older C limits.h). std::numeric_limits<int>::min() is roughly -2 billion (assuming 32 bit ints, etc.). But std::numeric_limits<float>::min() is smallest positive floating point value... something like +0.00000000000000000000000000000000000001. CppReference warns this is the case for all floating point types with denormalization (thus it applies to double and long … Continue reading Warning: std::numeric_limits::min() > 0

Understanding & Tracing Numerical Errors in C++

Notes on a talk by Gino van den Bergen (@dtecta) Fixed point numbers snap to a regular grid; in floating point numbers, the rounding error increases the farther you get from zero IEEE 754 single-precision (32-bit) float is: 1 bit for sign 8 bits for the exponent 23 bits for the fraction (-1)^sign * 1.fraction … Continue reading Understanding & Tracing Numerical Errors in C++

Benchmarks of Cache-Friendly Data Structures in C++

Suppose you're a savvy C++ developer who knows all about data-oriented design and the importance of optimizing for cache locality if you want a prayer of running fast on modern hardware. Now suppose you want to go beyond basics—"just use std::vector" is a good starting point, but you want more! I'm going to go over … Continue reading Benchmarks of Cache-Friendly Data Structures in C++

Conference Talk Playlists for C++ & Game Developers

I’ve put together a number of conference talk playlists for my own “professional development.” This is a list curated by going through hundreds of talks in the GDC and CppCon archives. I’ve tried to keep overlap between lists to a minimum. I’ve not watched everything (erm… obviously!), but in cases where I have watched a talk, … Continue reading Conference Talk Playlists for C++ & Game Developers

Esoteric Data Structures and Where to Find Them

This is a summary of the CppCon 2017 talk given by Allan Deutsch. Slot map An unordered, associative container similar to hash map Assigns items a unique identifier (unlike a hash map, where you provide an identifier) Similar to a pool allocator, but with a map-like interface Advantages over hash map: True constant time lookup, erase, … Continue reading Esoteric Data Structures and Where to Find Them

Notes from Andre Alexandrescu’s Modern C++ Design

Here are my highlights from Andre Alexandrescu's Modern C++ Design: Generic Programming and Design Patterns Applied. Policy-Based Class Design Overview: Policy-based class design fosters assembling a class with complex behavoir out of many little classes (called policies), each of which takes care of only one behavioral or structural aspect. The challenge in any design is … Continue reading Notes from Andre Alexandrescu’s Modern C++ Design