Guided Project 1: Industrial-Grade Dynamic String & Small String Optimization (SSO)
Engineer a high-performance custom dynamic string class implementing the full Rule of Five, dynamic buffer reallocation, null-termination invariants, and Small String Optimization (SSO).
By the end, you’ll be able to…
- Construct an industrial-grade string class implementing the complete Rule of Five with zero memory leaks
- Implement Small String Optimization (SSO) to store short strings (<= 15 bytes) on the stack without heap allocation
- Benchmark SSO string throughput against heap allocations under high-frequency iteration
01Project Architecture & Requirements
In this systems project, you will construct CustomString—a production-grade string class modeled after std::string. Building a string class is the ultimate crucible for mastering C++ memory management because it requires balancing dynamic heap growth, null-termination C-compatibility, deep copying, and O(1) move semantics.
Your implementation must fulfill the following technical specifications:
1. Dynamic Memory Management: Allocate null-terminated char buffers on the heap with geometric capacity doubling.
2. Rule of Five: Implement Destructor, Deep-Copy Constructor, Copy-and-Swap Assignment, Move Constructor (noexcept), and Move Assignment (noexcept).
3. Small String Optimization (SSO): Store strings of 15 characters or fewer directly inside a local stack buffer union, bypassing the heap allocator entirely!