A heap allocation (new, a growing std::vector, a std::string longer than its small built-in buffer, a std::function holding a large lambda) asks the allocator for memory. It is usually fast, sometimes slow, and it may take a lock, which is why latency-sensitive code keeps allocations off the hot path, the code that runs for every message or order. The rule: allocate at start-up, reuse while running.
The main tools are reserve(n), which sizes a vector once so push_back never reallocates while it stays under n; clear(), which empties a vector or string but keeps its memory for the next use; passing an output buffer in by reference instead of returning a fresh container from every call; writing numbers into a char buffer with std::to_chars; and taking a callable as a template parameter, which never allocates, instead of as a std::function, which can.
In these exercises the tests replace operator new with a version that counts. allocation_count() returns the number of heap allocations so far, so a test can check that a loop allocated nothing at all, the same check latency teams write into their own test suites.
Allocate once, then clear and refill: the hot path never calls the allocator.