optimizing-memory-allocation

optimizing-memory-allocation is a skill for Claude Code, Codex from christian289/dotnet-with-claudecode. It costs 33 tokens per session (1,162 once invoked), scanned A, original, MIT.

A guide to reducing temporary memory use in .NET programs with Span, ArrayPool, and ObjectPool. These tools reuse or view data without creating as many new objects for the garbage collector to clean up.

In plain words
What is it for?
Use it when parsing strings, slicing arrays, reusing buffers, pooling objects, or building high-throughput code that needs to limit extra memory allocations.
Why use it?
It helps reduce garbage-collection work in code that repeatedly parses, slices, or processes data, which can improve memory behavior in demanding workloads.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/christian289/dotnet-with-claudecode/optimizing-memory-allocation
Any agent
npx skills add christian289/dotnet-with-claudecode --skill optimizing-memory-allocation
Clone the repo
git clone --depth 1 https://github.com/christian289/dotnet-with-claudecode

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for optimizing-memory-allocation

README.md
[![agentmods](https://agentmods.dev/badge/skills/christian289/dotnet-with-claudecode/optimizing-memory-allocation.svg)](https://agentmods.dev/skills/christian289/dotnet-with-claudecode/optimizing-memory-allocation)
Your own site
<a href="https://agentmods.dev/skills/christian289/dotnet-with-claudecode/optimizing-memory-allocation"><img src="https://agentmods.dev/badge/skills/christian289/dotnet-with-claudecode/optimizing-memory-allocation.svg" alt="Measured on agentmods" height="20"></a>
Per session 33 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,162 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00033 $0.01162
Opus 5 $0.00016 $0.00581
Sonnet 5 $0.00007 $0.00232
Haiku 4.5 $0.00003 $0.00116

Measured 5d ago against content hash 89c6d1fd28fd, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

optimizing-memory-allocation scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

archive-skills/optimizing-memory-allocation/SKILL.md · 219 lines

How it starts

The opening of the file, as written. The whole thing — 219 lines — stays where its author put it; the contents beside it link to each section on GitHub.

.NET Memory Efficiency, Zero Allocation

A guide for APIs that minimize GC pressure and enable high-performance memory management.

Quick Reference: See QUICKREF.md for essential patterns at a glance.

1. Core Concepts

  • .NET CLR GC Heap Memory Optimization
  • Understanding Stack allocation vs Heap allocation
  • Stack-only types through ref struct

2. Key APIs

API Purpose NuGet
Span<T>, Memory<T> Stack-based memory slicing BCL
ArrayPool<T>.Shared Reduce GC pressure through array reuse BCL
DefaultObjectPool<T> Object pooling Microsoft.Extensions.ObjectPool
MemoryCache In-memory caching System.Runtime.Caching

3. Span, ReadOnlySpan

3.1 Basic Usage

// Zero Allocation when parsing strings
public void ParseData(ReadOnlySpan<char> input)
{
    // String manipulation without Heap allocation
    var firstPart = input.Slice(0, 10);
    var secondPart = input.Slice(10);
}

// Array slicing
public void ProcessArray(int[] data)
{
    Span<int> span = data.AsSpan();
    Span<int> firstHalf = span[..^(span.Length / 2)];
    Span<int> secondHalf = span[(span.Length / 2)..];
}

3.2 String Processing Optimization

// ❌ Bad example: Substring allocates new string
string part = text.Substring(0, 10);

// ✅ Good example: AsSpan has no allocation
ReadOnlySpan<char> part = text.AsSpan(0, 10);

3.3 Using with stackalloc

public void ProcessSmallBuffer()
{
    // Allocate small buffer on Stack (no Heap allocation)
    Span<byte> buffer = stackalloc byte[256];
    FillBuffer(buffer);
}

4. ArrayPool

Reduces GC pressure by reusing large arrays.

4.1 Basic Usage

namespace MyApp.Services;

public sealed class DataProcessor
{
    public void ProcessLargeData(int size)
    {
        // Rent array (minimize Heap allocation)
        var buffer = ArrayPool<byte>.Shared.Rent(size);

        try
        {
            // Use buffer (only use up to requested size)
            ProcessBuffer(buffer.AsSpan(0, size));
        }
        finally
        {
            // Must return
            ArrayPool<byte>.Shared.Return(buffer);
        }
    }
}

Read the full file on GitHub · 219 lines

Files

What ships with it

1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 219 lines · 33 tokens per session scan A 89c6d1fd28fd

Subscribe to this mod's changes

optimizing-memory-allocation is a skill published in the GitHub repository christian289/dotnet-with-claudecode (41 stars, last pushed 1mo ago), licensed MIT. It adds 33 tokens to every session and 1,162 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

nina-repository

Repository-specific guidance for working in the N.I.N.A. codebase and NINA.sln. Use when Codex is asked to modify, review, test, debug, navigate, or explain code in this repository; touch NINA. projects, app startup/DI, profiles/settings, localization, database migrations, equipment, astrometry, imaging, plate…

isbeorn/nina · 106 tokens

lightningcad

Use when doing architectural facade panel layout and detailing in AutoCAD or ZWCAD — panel numbering, shop drawing generation, material optimization. LightningCAD: building envelope detailing plugin for AutoCAD/ZWCAD.

znlgis/opengis-skills · 45 tokens

reogrid

Use when embedding an Excel-like spreadsheet control in .NET WinForms/WPF applications — formula engine, cell editing, clipboard, undo/redo. ReoGrid: .NET spreadsheet component with NPOI-based Excel read/write.

znlgis/opengis-skills · 50 tokens

mapsui

Use when embedding interactive 2D maps in .NET desktop (WinForms/WPF) or mobile (MAUI) applications — tile layers, vector features, map controls. Mapsui: cross-platform .NET map component library.

znlgis/opengis-skills · 49 tokens

nap

Reclaims context window budget by compressing agent histories, pruning old logs, archiving stale decisions, and cleaning orphaned inbox files.

dotnet/maui-labs · 0 tokens

orchardcore-ai-memory

Skill for configuring persistent, user-scoped AI Memory in Orchard Core using the CrestApps AI Memory module. Covers memory indexing backends (Azure AI Search and Elasticsearch), memory tools, preemptive memory retrieval, and per-profile memory settings. Use this skill when requests mention Orchard Core AI Memory…

CrestApps/CrestApps.AgentSkills · 166 tokens