home / skills / sickn33 / antigravity-awesome-skills / memory-safety-patterns
This skill helps you apply memory-safe patterns across Rust, C++, and C, ensuring RAII, ownership, and resource management.
npx playbooks add skill sickn33/antigravity-awesome-skills --skill memory-safety-patternsReview the files below or copy the command above to add this skill to your agents.
---
name: memory-safety-patterns
description: Implement memory-safe programming with RAII, ownership, smart pointers, and resource management across Rust, C++, and C. Use when writing safe systems code, managing resources, or preventing memory bugs.
---
# Memory Safety Patterns
Cross-language patterns for memory-safe programming including RAII, ownership, smart pointers, and resource management.
## Use this skill when
- Writing memory-safe systems code
- Managing resources (files, sockets, memory)
- Preventing use-after-free and leaks
- Implementing RAII patterns
- Choosing between languages for safety
- Debugging memory issues
## Do not use this skill when
- The task is unrelated to memory safety patterns
- You need a different domain or tool outside this scope
## Instructions
- Clarify goals, constraints, and required inputs.
- Apply relevant best practices and validate outcomes.
- Provide actionable steps and verification.
- If detailed examples are required, open `resources/implementation-playbook.md`.
## Resources
- `resources/implementation-playbook.md` for detailed patterns and examples.
This skill teaches cross-language memory-safety patterns for systems programming using RAII, ownership models, smart pointers, and disciplined resource management across Rust, C++, and C. It focuses on preventing leaks, use-after-free, and other common memory bugs while offering actionable guidance for design and debugging. The guidance is practical and targeted to engineers writing high-performance, reliable code.
I inspect the problem context, resource lifetimes, and existing ownership semantics, then recommend language-appropriate patterns (RAII in C++, ownership and borrowing in Rust, disciplined APIs in C). I provide concrete refactor steps, safe API sketches, and verification methods like static analysis, sanitizers, and unit tests. When requested, I map equivalent patterns across languages to help choose the safest implementation.
Can these patterns be applied incrementally to a large codebase?
Yes. Start by isolating resource-handling hotspots, add RAII wrappers or ownership types for those modules, and expand coverage while running sanitizers and tests.
How do I choose between smart pointers in C++?
Use unique ownership (unique_ptr) when a single owner exists, reference-counted (shared_ptr) when ownership must be shared, and raw pointers only for non-owning references. Prefer move semantics to transfer ownership.