No chapter on memory management would be complete without a brief discussion of fragmentation. Memory fragmentation refers to a process in which memory is broken up into chunks, often spread out, almost always resulting in the allocator's inability to allocate memory for an application, ultimately resulting in std::bad_alloc() being thrown in C++. When programming systems, fragmentation should always be a concern as it can dramatically impact the stability and reliability of your program, especially on resource-constrained systems, such as embedded and mobile applications. In this section, the reader will get a brief introduction to fragmentation, and how it affects the programs they create.
There are two types of fragmentation—external and internal fragmentation.