| name | memory-management |
| version | 3.0.0 |
| description | Production-grade skill for safe and efficient C++ memory management. Covers RAII, smart pointers, custom allocators, memory pools, and leak detection techniques.
|
| sasmp_version | 1.3.0 |
| skill_version | 3.0.0 |
| bonded_agent | 02-memory-specialist |
| bond_type | PRIMARY_BOND |
| category | learning |
| parameters | {"topic":{"type":"string","required":true,"enum":["raii","smart_pointers","allocators","pools","debugging","ownership"]},"issue_type":{"type":"string","required":false,"enum":["leak","corruption","dangling","overflow"]}} |
| error_handling | {"retry_logic":{"max_attempts":3,"backoff":"exponential","initial_delay_ms":500,"jitter":true},"fallback":{"on_leak_detected":"suggest_raii_wrapper","on_corruption":"run_with_sanitizer"}} |
Memory Management Skill
Production-Grade Learning Skill | Safe Resource Handling
Master C++ memory management for safe, efficient, and leak-free code.
Core Principles
The Golden Rule: RAII
Resource Acquisition Is Initialization
class FileHandle {
FILE* handle_{nullptr};
public:
explicit FileHandle(const char* path, const char* mode)
: handle_(fopen(path, mode))
{
if (!handle_) {
throw std::runtime_error("Failed to open file");
}
}
~FileHandle() {
if (handle_) fclose(handle_);
}
FileHandle(const FileHandle&) = delete;
FileHandle& operator=(const FileHandle&) = delete;
FileHandle(FileHandle&& other) noexcept
: handle_(std::exchange(other.handle_, nullptr)) {}
FileHandle& operator=(FileHandle&& other) noexcept {
if (this != &other) {
if (handle_) fclose(handle_);
handle_ = std::(other.handle_, );
}
*;
}
{ handle_; }
};
{
;
}