{"enrichment":{"faq":[{"a":"Swift's Span type provides safe, zero-cost access to contiguous memory without the overhead of Array's copy-on-write semantics. memory uses Span as a non-escapable view over existing storage\u2014pass it to functions that need read-only access to a buffer without copying. For mutable access, use MutableSpan. Both are compiler-checked alternatives to UnsafeBufferPointer, eliminating bounds-checking overhead while preserving memory safety in performance-critical code.","q":"How to use Span for memory access in Swift 6.2?"},{"a":"memory's InlineArray is a fixed-size collection that stores elements directly inline\u2014no heap allocation, no copy-on-write. Use InlineArray when you need a small, compile-time-sized collection in hot paths: signal processing, embedded Swift, or any scenario where eliminating allocations matters. InlineArray guarantees zero-copy semantics and provides compile-time size validation, making it ideal for replacing hand-tuned tuple storage or small Array instances.","q":"What is InlineArray and when should I use it?"},{"a":"memory's Span types (Span, MutableSpan, RawSpan, UTF8Span) are compiler-checked safe alternatives to UnsafeBufferPointer. They enforce non-escapable lifetimes at compile time, preventing use-after-free bugs. Migrate by replacing UnsafeBufferPointer views with the appropriate Span variant: Span for typed read-only, MutableSpan for typed mutable, RawSpan for untyped binary data, UTF8Span for Unicode text. No runtime overhead\u2014same performance, better safety.","q":"How does memory help replace UnsafeBufferPointer with Span?"},{"a":"Yes. memory combines InlineArray for fixed-size inline storage with Span for zero-copy views over existing buffers. Together they eliminate the heap allocations and copy-on-write overhead that small Array instances incur. In performance-critical loops, replace Array with InlineArray (when size is known) and pass buffers as Span instead of copying. This keeps data on the stack and reduces GC pressure in embedded and real-time contexts.","q":"Can memory eliminate heap allocations in Swift hot paths?"},{"a":"memory's RawSpan provides safe, untyped access to binary data\u2014ideal for parsing protocols, file formats, or network packets without unsafe casts. UTF8Span specializes in Unicode text processing, offering safe iteration and validation over UTF-8 bytes. Both are non-escapable views that prevent lifetime violations while maintaining zero-copy performance, making them essential for signal processing, embedded systems, and any binary I/O where safety and speed matter equally.","q":"What are RawSpan and UTF8Span used for?"},{"a":"Yes. memory's InlineArray uses value generics (let count: Int) to encode fixed sizes at compile time, enabling the compiler to validate bounds and eliminate runtime checks. This compile-time guarantee means InlineArray storage is allocated inline with no heap indirection. The result: type-safe, zero-allocation fixed-size collections that the optimizer can fully specialize, delivering performance equivalent to hand-written C while maintaining Swift's memory safety.","q":"Does memory support value generics and compile-time size guarantees?"}],"shadow_tags":["low-level-memory","stack-storage","zero-allocation","safe-pointers","performance-critical","embedded-systems","binary-data","lifetime-safety","contiguous-buffers","value-semantics"],"summary_rewrite":"Learn Swift 6.2's low-level memory types designed for performance-critical code: InlineArray for fixed-size inline storage without heap allocation, and Span for safe, zero-cost access to contiguous memory. These compiler-checked alternatives replace common uses of UnsafeBufferPointer and hand-tuned tuple storage, helping you eliminate allocations in hot paths while maintaining memory safety."},"files":[{"bytes":13322,"path":"skills/swift/memory/SKILL.md","sha256":"71bf7bb3ecc9fac15eb80c047006141291c277ef4fedafac074c66f3df945c27","url":"https://skillfed.io/files/rshankras/claude-code-apple-skills/memory/825b64ae/SKILL.md"}],"id":"rshankras/claude-code-apple-skills/memory","links":{"html":"https://skillfed.io/rshankras/claude-code-apple-skills/memory","md":"https://skillfed.io/rshankras/claude-code-apple-skills/memory.md","repo":"https://github.com/rshankras/claude-code-apple-skills"},"meta":{"agents_supported":[],"first_seen":"2026-07-28","forks":47,"language":"Swift","last_updated":"2026-07-24","license":"MIT","name":"memory","publisher":"rshankras","stars":565},"relations":{"similar":[{"id":"rshankras/claude-code-apple-skills/swift"},{"id":"CharlesWiltgen/Axiom/axiom-swift"},{"id":"sammcj/agentic-coding/swift-development"},{"id":"CharlesWiltgen/Axiom/axiom-apple-docs"},{"id":"xu-xiang/everything-claude-code-zh/swift-concurrency-6-2"},{"id":"rshankras/claude-code-apple-skills/concurrency"},{"id":"xtone/ai_development_tools/swift-ios-migration"},{"id":"dpearson2699/swift-ios-skills/swift-language"},{"id":"affaan-m/ECC/swift-concurrency-6-2"},{"id":"rshankras/claude-code-apple-skills/concurrency-patterns"}]},"slug":{"owner":"rshankras","repo":"claude-code-apple-skills","skill":"memory"},"version":"825b64ae"}
