Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsBlogPro
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Authors
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges
  • Chrome Extension
  • Skill Manager

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

ProTermsPrivacyRefunds
Back to skills

Memory Allocators Arenas C

ASecurity

Design, implement, and verify high-performance custom memory allocators in C and C++. Build Arena / Bump allocators, Pool / Fixed-size block allocators, and Free-List allocators. Ensure strict hardware memory alignment (alignof, power-of-two boundaries), zero-fragmentation lifecycles, and cache line locality. Trigger when building game engines, high-frequency trading (HFT) engines, or embedded runtime systems.

8 stars
0 votes
0 copies
0 views
Added 9/29/2026
ai-agentsgoc++nodeperformance

Security Analysis

A100/100

Scanned 9/29/2026

$npx -y skills add hamzabellouch/agent-skills --skill memory-allocators-arenas-c --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Memory Allocators Arenas C?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Memory Allocators Arenas C
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hamzabellouch-memory-allocators-arenas-c/badge)](https://www.skillsdirectory.com/skills/hamzabellouch-memory-allocators-arenas-c)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
Files
SKILL.md
---
name: memory-allocators-arenas-c
metadata:
  category: Low-Level Systems Drivers and Kernel
description: Design, implement, and verify high-performance custom memory allocators in C and C++. Build Arena / Bump allocators, Pool / Fixed-size block allocators, and Free-List allocators. Ensure strict hardware memory alignment (alignof, power-of-two boundaries), zero-fragmentation lifecycles, and cache line locality. Trigger when building game engines, high-frequency trading (HFT) engines, or embedded runtime systems.
compatibility: C99 / C11, C++17, POSIX / Windows memory primitives
---

# Custom Memory Allocators & Arenas Skill Guide

This skill specifies algorithms, pointer arithmetic patterns, and hardware alignment requirements for implementing zero-overhead custom memory allocators in C and C++.

---

## 1. Allocator Topologies & Trade-offs

```text
+-----------------------+-----------------------+-----------------------+
| Allocator Type        | Allocation Time       | Deallocation Strategy |
+-----------------------+-----------------------+-----------------------+
| Arena (Bump)          | O(1) pointer addition | O(1) Reset all at once|
| Pool (Fixed-Size)     | O(1) pop free-list    | O(1) push free-list   |
| Free-List (Segregated)| O(N) or O(log N)      | Coalesce adjacent free|
+-----------------------+-----------------------+-----------------------+
```

---

## 2. Production C Implementation: Arena & Pool Allocators

### A. High-Performance Hardware-Aligned Arena Allocator

```c
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>

#define DEFAULT_ALIGNMENT (sizeof(void*))

typedef struct {
    uint8_t *buffer;
    size_t capacity;
    size_t offset;
    size_t prev_offset;
} MemoryArena;

static inline uintptr_t align_forward(uintptr_t ptr, size_t alignment) {
    assert((alignment & (alignment - 1)) == 0 && "Alignment must be power of two");
    uintptr_t a = (uintptr_t)alignment;
    return (ptr + a - 1) & ~(a - 1);
}

void arena_init(MemoryArena *arena, void *backing_buffer, size_t capacity) {
    arena->buffer = (uint8_t*)backing_buffer;
    arena->capacity = capacity;
    arena->offset = 0;
    arena->prev_offset = 0;
}

void *arena_alloc_aligned(MemoryArena *arena, size_t size, size_t alignment) {
    uintptr_t current_ptr = (uintptr_t)arena->buffer + (uintptr_t)arena->offset;
    uintptr_t aligned_ptr = align_forward(current_ptr, alignment);
    size_t padding = aligned_ptr - current_ptr;

    if (arena->offset + padding + size > arena->capacity) {
        return NULL; // Out of memory
    }

    arena->prev_offset = arena->offset;
    arena->offset += padding + size;

    return (void*)aligned_ptr;
}

void *arena_alloc(MemoryArena *arena, size_t size) {
    return arena_alloc_aligned(arena, size, DEFAULT_ALIGNMENT);
}

void arena_reset(MemoryArena *arena) {
    // Instant O(1) deallocation of all allocated memory
    arena->offset = 0;
    arena->prev_offset = 0;
}
```

### B. Fixed-Size Block Pool Allocator

```c
typedef struct PoolFreeNode {
    struct PoolFreeNode *next;
} PoolFreeNode;

typedef struct {
    uint8_t *buffer;
    size_t block_size;
    size_t capacity;
    PoolFreeNode *free_list;
} MemoryPool;

void pool_init(MemoryPool *pool, void *backing_buffer, size_t total_size, size_t block_size) {
    assert(block_size >= sizeof(PoolFreeNode) && "Block size must fit free node pointer");
    pool->buffer = (uint8_t*)backing_buffer;
    pool->block_size = block_size;
    pool->capacity = total_size;
    pool->free_list = NULL;

    // Chain all blocks into the free list
    size_t num_blocks = total_size / block_size;
    for (size_t i = 0; i < num_blocks; ++i) {
        PoolFreeNode *node = (PoolFreeNode*)(pool->buffer + (i * block_size));
        node->next = pool->free_list;
        pool->free_list = node;
    }
}

void *pool_alloc(MemoryPool *pool) {
    if (!pool->free_list) {
        return NULL; // Pool exhausted
    }
    PoolFreeNode *node = pool->free_list;
    pool->free_list = node->next;
    return (void*)node;
}

void pool_free(MemoryPool *pool, void *ptr) {
    if (!ptr) return;
    PoolFreeNode *node = (PoolFreeNode*)ptr;
    node->next = pool->free_list;
    pool->free_list = node;
}
```

---

## 3. Best Practices & Hardware Guidelines

1. **Power-of-Two Alignment:** Always enforce that alignments are powers of two (`(align & (align - 1)) == 0`).
2. **Cache Line Locality:** For high-throughput structs, align to 64 bytes (`alignas(64)`) to avoid false sharing across CPU cores.
3. **Double Free Elimination:** Arena allocators completely eliminate individual double-free and memory fragmentation bugs because memory is only reclaimed en masse.

Attribution

hamzabellouchhamzabellouch
View sourceSee grades on GitHubMore from hamzabellouch →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Caveman

Terse caveman voice: answer first, fluff gone, every technical fact kept. Use for /caveman, "caveman mode", "talk like caveman", "be brief", "less tokens". Stays on until "stop caveman" or "normal mode".

1100021 votes

Hyperplan

Adversarial multi-agent planning skill. Self-orchestrates 5 hostile category members (unspecified-low, unspecified-high, deep, ultrabrain, artistry) via team-mode for ruthless cross-critique debate, distills only the defensible insights, then MANDATORILY hands the distilled insight bundle to the `plan` agent for executable plan formalization. Use when planning needs maximum rigor and surfacing of weak assumptions, blind spots, and over-engineering. Triggers: 'hyperplan', 'hpp', '/hyperplan', ...

698621 votes

Writing Skills

Create and manage Claude Code skills in HASH repository following Anthropic best practices. Use when creating new skills, modifying skill-rules.json, understanding trigger patterns, working with hooks, debugging skill activation, or implementing progressive disclosure. Covers skill structure, YAML frontmatter, trigger types (keywords, intent patterns), UserPromptSubmit hook, and the 500-line rule. Includes validation and debugging with SKILL_DEBUG. Examples include rust-error-stack, cargo-dep...

3931 votes

Mcp Code Execution

Routes multi-tool workflows through MCP servers for large datasets and pipelines. Use when Bash tool overhead is limiting throughput on data-heavy tasks.

3421 votes

catchup

Recovers the conversation and failed tool calls of a previous Codex, Amp, Claude Code, Antigravity, Cline, Copilot CLI, Cursor, DeepSeek Harness, Grok Build, Kimi, OpenCode, Pi Agent, or ZCode session. Use when the user says "catch up", "what did the last session do", "get me up to speed", "I switched agents", asks to recover/summarize a previous session before continuing, or asks to diagnose or report a catchup failure. Do NOT use for the current conversation, git history, or any non-agent log.

741 votes
View all in ai-agents →