agentleFS
rainoftimerainoftime/pl-skills/memory-allocator/SKILL.md

memory-allocator

Skill17 starsChanged 9 months agoApache-2.0View on GitHub

Implement memory allocators for efficient dynamic memory management in language runtimes.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use slab allocators for fixed-size objects

    line 43
  2. Distinctive:

    Use arena allocators for temporary allocations

    line 44
  3. Distinctive:

    Use generation counters for safe references

    line 47
  4. Distinctive:

    When OS allocator suffices

    line 83
  5. Distinctive:

    When memory is not a concern

    line 85

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Memory Allocator

Memory allocators manage dynamic memory allocation and deallocation, a critical component of language runtimes. Different allocation strategies optimize for different workloads.

When to Use This Skill

  • Implementing language runtimes
  • Building custom allocators
  • Optimizing memory performance
  • Embedded systems development
  • Understanding memory management

What This Skill Does

  1. Block Allocation: Allocate fixed-size blocks efficiently
  2. Heap Management: Organize free memory
  3. Allocation Strategies: First-fit, best-fit, segregated fit
  4. Fragmentation Control: Minimize internal/external fragmentation
  5. Deallocation: Free memory and coalesce blocks

Key Concepts

ConceptDescription
BlockContiguous memory region
FragmentationWasted space (internal or external)
Free ListLinked list of free blocks
CoalescingMerge adjacent free blocks
SlabPre-allocated block for fixed-size objects

Tips

  • Use slab allocators for fixed-size objects
  • Use arena allocators for temporary allocations
  • Consider alignment requirements
  • Profile before optimizing allocation
  • Use generation counters for safe references

Common Use Cases

  • Language runtime allocators
  • Game engines (arena allocators)
  • Database buffer pools
  • Embedded systems
  • High-performance systems

Related Skills

  • garbage-collector-implementer - Automatic memory management
  • escape-analysis - Optimize allocation
  • jit-compiler-builder - JIT allocation

Canonical References

ReferenceWhy It Matters
Wilson et al., "Dynamic Storage Allocation" (1994)Survey of algorithms
Bonwick, "The Linux Slab Allocator" (USENIX 1994)Linux slab allocator
Berger, McKinley, Blumofe & Wilson, "Hoard: A Scalable Memory Allocator for Multithreaded Applications" (ASPLOS 2000)Scalable multicore allocator

Tradeoffs and Limitations

Approach Tradeoffs

ApproachProsCons
Bump pointerVery fastCannot free individually
Free listCan freeFragmentation
SlabNo fragmentationFixed size only

When NOT to Use This Skill

  • When OS allocator suffices
  • For small programs
  • When memory is not a concern

Limitations

  • Thread safety requires synchronization
  • Fragmentation is hard to eliminate
  • Cannot allocate more than capacity

Assessment Criteria

A high-quality implementation should have:

CriterionWhat to Look For
CorrectnessNo corruption, double-free safe
EfficiencyLow allocation overhead
FragmentationReasonable memory usage
SafetyBounds checking

Quality Indicators

✅ Good: Correct, efficient, handles edge cases ⚠️ Warning: Fragmentation issues ❌ Bad: Memory corruption, crashes

Research Tools & Artifacts

Real-world memory allocators:

ToolWhy It Matters
jemallocFacebook allocator
tcmallocGoogle allocator
HoardScalable allocator
snmallocMicrosoft's allocator
RPMallocFast allocator

Key Systems

  • jemalloc: Production allocator
  • tcmalloc: glibc allocator

Research Frontiers

Current allocator research:

DirectionKey PapersChallenge
Scalable"Scalable Allocators"Multi-core
NUMA"NUMA-aware"Memory hierarchy
Large"Large allocators"Big data

Hot Topics

  1. Allocator for Wasm: WebAssembly allocation
  2. Allocator for Rust: Custom allocators

Implementation Pitfalls

Common allocator bugs:

PitfallReal ExamplePrevention
FragmentationMemory fragmentationSlab alloc
Thread contentionLock contentionPer-thread pools
MemoryMemory corruptionBounds checking

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.