memory-safety-patterns

Guide developers to implement memory-safety patterns in C, C++, and Rust.

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/ekremmkasap/jarvis --skill memory-safety-patterns-ekremmkasap
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: memory-safety-patterns
Source: https://github.com/ekremmkasap/jarvis/tree/main/server/agent_prompts/wshobson/plugins/systems-programming/skills/memory-safety-patterns
Command: npx skills add https://github.com/ekremmkasap/jarvis --skill memory-safety-patterns-ekremmkasap

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill provides a structured set of memory-safety patterns and proven techniques to help developers prevent common memory bugs and undefined behavior across C, C++, and Rust.

Core Features & Use Cases

  • RAII, ownership, and smart pointers to manage resource lifetimes automatically.
  • Language-specific patterns mapped to safe resource handling, concurrency, and memory management.
  • Use cases include systems programming, file/socket/resource handling, and performance-critical components where safety and correctness matter.

Quick Start

Review the documented patterns and apply RAII, ownership, and smart-pointer strategies in your codebase to reduce memory bugs.

Frequently Asked Questions about memory-safety-patterns

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

FAQPage Schema
How do I implement RAII and smart pointers for memory safety in C++?

Memory safety in C++ uses RAII to bind resource lifetimes to object scope, ensuring automatic cleanup and preventing leaks. Smart pointers manage dynamic memory automatically, eliminating manual deallocation errors and undefined behavior in systems programming.

What is the best way to manage resource ownership across C, C++, and Rust?

Cross-language resource ownership applies language-agnostic patterns: RAII and smart pointers in C++, strict ownership in Rust, and disciplined manual resource handling in C. This ensures correct lifetime management and prevents undefined behavior across systems programming components.

Does this memory safety approach work for systems programming and performance-critical components?

Yes, these memory safety patterns apply directly to systems programming and performance-critical components. The techniques codify safe resource handling, file and socket management, and concurrency patterns without sacrificing the low-level control required for high-performance applications.

How do ownership rules in Rust prevent common memory bugs and undefined behavior?

Rust ownership rules enforce strict compile-time lifetime and borrowing checks to prevent memory bugs. This guarantees every resource has a single owner, eliminating dangling pointers, data races, and double frees without runtime overhead in performance-critical code.

When should I not use smart pointers for resource management in C++?

You should avoid smart pointers when managing non-memory resources or when interfacing with C APIs that expect raw pointers. In these cases, incorrect smart pointer usage can hide ownership bugs or cause cycles, so careful manual resource handling or custom deleters are required.