A structured learning path through C++ fundamentals with emphasis on memory safety, RAII principles, and modern C++ practices.
- Master memory management and debugging techniques
- Understand RAII (Resource Acquisition Is Initialization) principles
- Learn smart pointer usage and move semantics
- Practice exception-safe programming
- Build thread-safe applications
Foundation concepts with focus on memory management and debugging:
- Memory Debugging: Practice with AddressSanitizer and Valgrind
- Memory Pools: Custom allocator implementations
- Stack/Heap Safety: Understanding memory layout and limits
- Performance Analysis: Comparing debugging tools
Key Files:
memory_demo.cpp- Basic memory management examplesmemory_pool.cpp- Custom allocator implementationtest_memory.sh- Automated testing with multiple toolsperformance_comparison.cpp- Tool performance analysis
Advanced memory safety using modern C++ features:
- Exception safety guarantees
- Resource management patterns
- Scope-based cleanup
- RAII violations and solutions
unique_ptr: Exclusive ownershipshared_ptr: Shared ownership with reference countingweak_ptr: Breaking circular references- Custom deleters and factories
- Move constructors and operators
- Perfect forwarding
- Move-only types
- Performance optimization
cd phase2_memory_safety/
mkdir -p build && cd build
cmake ..
make
ctest # Run automated tests# Phase 1 (C++17)
g++ -std=c++17 -g -Wall -Wextra -pthread program.cpp -o program
# Phase 2 (C++20)
g++ -std=c++20 -g -Wall -Wextra -pthread program.cpp -o programFast runtime detection of memory errors:
g++ -std=c++17 -fsanitize=address -fsanitize=leak -g -O1 program.cpp -o program
./programComprehensive memory analysis:
g++ -std=c++17 -g -O0 program.cpp -o program # No sanitizers
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./programg++ -std=c++17 -g -Wall -Wextra -Wpedantic -Wconversion -Wshadow program.cpp -o programphase1_fundamental/test_memory.sh- Comprehensive testingphase1_fundamental/test_both_tools.sh- Tool comparison
- RAII: Constructor acquires, destructor releases
- Exception Safety: Guaranteed cleanup during exceptions
- Thread Safety: Proper mutex usage with scoped locking
- Move Semantics: Efficient resource transfer
Each week builds upon previous concepts:
- Week 3: Daily RAII exercises with increasing complexity
- Week 4: Smart pointer progression (unique → shared → weak)
- Week 5: Move semantics and performance optimization
- Clone and explore: Start with
phase1_fundamental/memory_demo.cpp - Run tests: Use provided scripts to verify your environment
- Follow progression: Complete phases sequentially
- Debug actively: Use both AddressSanitizer and Valgrind
- Build with CMake: Use the automated build system for Phase 2
- Write code following RAII principles
- Test with AddressSanitizer during development (
-O1) - Verify with Valgrind for comprehensive checking (
-O0) - Use CMake Debug configuration for automatic tool integration
- Run automated tests with CTest
- Check
output/directories for compiled binaries
- Start with
phase1_fundamental/memory_demo.cpp - Practice with memory testing scripts
- Understand stack vs heap allocation
- Master RAII patterns in
week3/ - Learn smart pointer usage in
week4/ - Explore exception safety mechanisms
- Implement move semantics in
week5/ - Build thread-safe applications
- Optimize performance with modern C++ features
All code must meet these requirements:
- ✅ Zero memory leaks (verified by both tools)
- ✅ Exception safety maintained
- ✅ Thread safety for concurrent code
- ✅ Proper RAII implementation
- Comprehensive Testing: Multiple debugging tools and automated scripts
- Progressive Learning: Each phase builds upon previous knowledge
- Real-world Examples: Practical applications, not toy programs
- Modern C++: Focus on C++17/20 features and best practices
- Memory Safety: Emphasis on leak-free, exception-safe code
This repository emphasizes learning through practical implementation of memory-safe C++ patterns rather than theoretical examples.