Command Palette

Search for a command to run...

Назад к скиллам
скилл № 27180

memory-management

Use when the user asks about game engine memory, arena allocators, pool allocators, frame allocators, fragmentation, memory tracking and budgets…

БесплатноБез исполняемых скриптов
j4flmaoот j4flmao★ 47 звёзд на GitHub

Установить memory-management в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

Game Engine Memory Management — Deep Engineering Guide

Purpose

Memory behaviour is one of the most common sources of frame-time jank in shipped games. A 15 ms GC stop-the-world, a cache miss chain, or a fragmented heap turns a 60 FPS target into slideshow. This skill covers the full memory stack of a production game engine: from the raw allocator hierarchy, through cache-aware data layout, to memory tracking and GPU memory management.

Agent Protocol

Trigger

"game memory", "arena allocator", "pool allocator", "frame allocator", "memory fragmentation", "memory tracking", "cache layout", "GC spikes".

Input Context

  • Language/runtime (C++, C# with GC, Rust)
  • Platform memory limits
  • Profiler/tracker data

Output Artifact

Allocator design and code plus a memory budget table. No file unless requested.

Response Format

Allocator: {type, lifetime scope}
Budget: {category -> MB}
Code: {snippet}
Tracking: {how leaks/overruns are caught}

1. The Memory Model of a Game

1.1 Where Memory Goes

Region Owner Illustrative budget (large PC title; set your own per platform)
Code + read-only data OS loader 50–200 MB
Simulation (ECS archetypes) World/systems 200–800 MB
Assets (textures, meshes, audio) Asset manager 1–4 GB
Render resources (VB/IB/UBO, RT) Rendering backend 1–3 GB
Per-frame scratch Frame allocators 32–256 MB (transient)
Streaming pools Streaming system 256–1024 MB

The point is not the absolute numbers — it's that every subsystem owns its memory. Never let subsystems walk the same heap.

1.2 The Allocation Spectrum

owned     <— deterministic, hot, performance-critical —>      shared
arena / pool / stack           free-list / slabs             system heap / GC

1.3 Golden Rules

  1. No allocation in the hot loop. Capability, not preference: all physics, gameplay, and render-command generation run in pre-allocated arenas.
  2. Ownership is explicit. Every subsystem declares its memory regions at init: size, allocator, budget.
  3. Transient is transient. Per-frame scratch dies at frame end; nothing holds a pointer past Present().
  4. Measure. If memory isn't tracked per subsystem, you're flying blind on console cert (memory budget is a certification criterion on consoles).

2. The Allocator Hierarchy

System heap (malloc / new)      — last resort, slow, fragmented
   ├── Stack allocator           per-frame scratch, O(1) reset, no free
   ├── Arena / Bump allocator    monotonic one-shot regions, O(1) alloc
   ├── Free-list allocator       variable sizes; first/best-fit search is O(free blocks), size-class bins make it ~O(1)
   ├── Pool allocator            fixed block size, no fragmentation, O(1)
   └── Object pools              dedicated recycling for hot objects, type-safe
Allocator Alloc Free Fragment Usu
Stack O(1) O(1) reset none frame scratch
Arena O(1) — (reset) none one-shot regions
Pool O(1) O(1) none fixed-size objects
Free-list O(n) fit search (O(1) with size classes / TLSF) O(1) (+ coalescing) medium mixed sizes
System heap variable variable high rare

2.1 Stack Allocator (Frame Scratch)

class StackAllocator {
    uint8_t* buffer; size_t size; size_t top = 0;
public:
    explicit StackAllocator(size_t n) : size(n) {
        n = (n + 15) & ~size_t(15);                       // aligned_alloc needs size % align == 0
        buffer = static_cast<uint8_t*>(std::aligned_alloc(16, n)); // MSVC: _aligned_malloc/_aligned_free
        if (!buffer) throw std::bad_alloc();
    }
    void* alloc(size_t n, size_t align = 16) {
        size_t p = (top + align - 1) & ~(align - 1);
        void* r = buffer + p; top = p + n;
        ASSERT(top <= size);
        return r;
    }
    void reset() { top = 0; }          // whole frame's scratch freed at once
    ~StackAllocator() { std::free(buffer); }
};

Perfect for: collision pair lists, render command batches, input events, pathfinding open sets.

2.2 Arena / Linear Allocator

Identical mechanics to a stack without free — for one-shot regions built once (a level's static geometry, an audio bank). Some arenas support "double buffering": write region A while system reads region B, swap every frame.

2.3 Pool Allocator

template <typename T>
class ObjectPool {
    std::vector<T> storage;                      // contiguous! cache-friendly
    std::vector<uint32_t> freeList;              // indices of free slots
    bit-vector inUse;                             // O(1) "is this handle alive?"
public:
    template <typename... Args> Handle<T> emplace(Args&&...);
    void release(Handle<T> h);
    T* get(Handle<T> h);                          // bounds-checked, generation-tagged
};

Keys: contiguous storage (iteration caches), **genera

Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • references/allocator-hierarchy.md
  • references/cache-aware-layout.md
  • references/gc-avoidance.md
  • references/gpu-memory.md
  • references/memory-tracking.md
  • references/virtual-memory.md

FAQ

Что делает скилл memory-management?

Use when the user asks about game engine memory, arena allocators, pool allocators, frame allocators, fragmentation, memory tracking and budgets, cache-friendly layout or GC spikes. Produces an allocator hierarchy and budget tracking. Not for embedded static-only allocation (use c-cpp-patterns).

Как установить скилл memory-management?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл memory-management запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить memory-management с