memory

Replace UnsafePointer types with safe Span and InlineArray alternatives in Swift.

27|5|Updated Apr 18, 2026
One-click install
npx skills add https://github.com/bocan/bocan-music --skill memory-bocan
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: memory
Source: https://github.com/bocan/bocan-music/tree/main/.claude/skills/swift/memory
Command: npx skills add https://github.com/bocan/bocan-music --skill memory-bocan

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill solves the problem of unsafe, heap-allocated memory access in Swift performance-critical code, eliminating the need for error-prone UnsafePointer types while reducing runtime overhead from copy-on-write and reference counting.

Core Features & Use Cases

  • Fixed-Size Stack Storage: Use InlineArray for compile-time sized collections stored inline with no heap allocation or reference counting, ideal for small fixed data like color components or matrix rows.
  • Safe Contiguous Memory Access: Use the Span family (Span, MutableSpan, RawSpan, UTF8Span) for zero-cost, compiler-checked access to contiguous memory instead of legacy unsafe pointers.
  • Use Case: Optimize hot paths like binary parsing, signal processing, or embedded Swift code where heap allocation overhead and unsafe pointer errors are unacceptable.

Quick Start

Use the memory skill to replace your existing UnsafeBufferPointer usage in the audio buffer processing function with a safe Span implementation.

Frequently Asked Questions about memory

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

FAQPage Schema
What is the best way to avoid heap allocation overhead in Swift performance-critical code?

You can avoid heap allocation overhead in Swift by using InlineArray for compile-time sized stack storage and Span for safe contiguous memory access, eliminating reference counting and copy-on-write costs in hot paths.

How do I replace UnsafePointer types when binary parsing in Swift?

To replace UnsafePointer types in Swift binary parsing, use the Span family (Span, MutableSpan, RawSpan, UTF8Span) which provides zero-cost, compiler-checked, lifetime-safe contiguous memory access instead of legacy unsafe pointers.

When do I need fixed-size stack-allocated collections in Swift?

You need fixed-size stack-allocated collections in Swift when handling small fixed data like color components or matrix rows where heap allocation and reference counting overhead are prohibitive, using InlineArray for compile-time checked inline storage.

Can I use Span for memory access in embedded Swift development?

Yes, you can use Span for memory access in embedded Swift development where heap allocation overhead and unsafe pointer errors are unacceptable, providing lifetime-safe contiguous memory access aligned with Swift 6.2 language features.

Why does copy-on-write cause performance issues in Swift signal processing hot paths?

Copy-on-write causes performance issues in Swift signal processing hot paths due to runtime overhead from reference counting and unexpected data duplication, which you can eliminate by replacing heap-heavy collections with zero-overhead InlineArray and Span.