memory-safety-patterns

Implement memory-safe patterns in Rust, C++, and C with RAII and smart pointers.

2|Updated Jan 18, 2026
One-click install
npx skills add https://github.com/as4584/antigravity-skills --skill memory-safety-patterns-as4584
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: memory-safety-patterns
Source: https://github.com/as4584/antigravity-skills/tree/main/agents-wshobson/plugins/systems-programming/skills/memory-safety-patterns
Command: npx skills add https://github.com/as4584/antigravity-skills --skill memory-safety-patterns-as4584

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the critical challenge of memory management and resource handling in systems programming, preventing common bugs like memory leaks, use-after-free errors, and data races.

Core Features & Use Cases

  • Cross-Language Patterns: Provides implementations and explanations for memory safety in Rust, C++, and C.
  • RAII & Ownership: Demonstrates Resource Acquisition Is Initialization and Rust's ownership model for automatic resource management.
  • Smart Pointers: Explains unique_ptr, shared_ptr, and weak_ptr for safe memory management in C++.
  • Bounds Checking: Illustrates safe array/vector access and the importance of bounds checking.
  • Data Race Prevention: Covers std::atomic, std::mutex, std::shared_mutex in C++ and Arc, Mutex, RwLock, Atomic in Rust.
  • Use Case: When developing a high-performance network service in C++ or Rust, ensuring memory safety and preventing data races is paramount. This skill provides the patterns and tools to achieve that.

Quick Start

Explain the RAII pattern in C++ with a code example.

Frequently Asked Questions about memory-safety-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent use-after-free and double-free bugs in C++?

Prevent use-after-free and double-free bugs in C++ by applying RAII patterns and smart pointers like unique_ptr and shared_ptr to automate resource lifecycle management and ownership.

What is the best way to avoid data races in Rust?

Avoid data races in Rust by using concurrency primitives like Arc, Mutex, RwLock, and Atomic types to ensure safe shared state across threads. This enforces strict ownership rules at compile time.

How does RAII help with memory safety in systems programming?

RAII ensures memory safety by binding resource lifecycles to object scope, automatically releasing memory and preventing leaks. It forms the core of automatic resource management in C++ and Rust.

Can I implement bounds checking for buffer overflows in C?

Implement bounds checking in C to prevent buffer overflows by manually validating array indices against limits before access. Memory safety patterns provide safe array access techniques and debugging tool recommendations.

Rust ownership vs C++ smart pointers for resource management?

Rust ownership enforces memory safety at compile time via borrow checks, whereas C++ smart pointers manage resources dynamically. Both prevent dangling pointers and leaks but differ in runtime overhead guarantees.