memory_arena
Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions
arena_hooks.h File Reference

Allocation hook system for arena-based memory tracking and introspection. More...

#include <stdatomic.h>
+ Include dependency graph for arena_hooks.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  s_arena_hooks
 Internal structure for managing arena hooks. More...
 

Typedefs

typedef void(* arena_allocation_hook) (t_arena *arena, int alloc_id, void *ptr, size_t size, size_t offset, size_t wasted, const char *label)
 Allocation hook callback type.
 
typedef struct s_arena t_arena
 Forward declaration of arena structure.
 
typedef struct s_arena_hooks t_arena_hooks
 Internal structure for managing arena hooks.
 

Functions

void arena_set_allocation_hook (t_arena *arena, arena_allocation_hook cb, void *context)
 Set or remove an allocation hook on a given arena.
 

Detailed Description

Allocation hook system for arena-based memory tracking and introspection.

Author
Toonsa
Date
2025

This module allows users to attach custom callback functions (hooks) to arena allocators. These hooks are triggered after each successful allocation, providing detailed metadata for logging, profiling, or visualization tools.

Features:

Typical use cases:

Note
The hook mechanism is lightweight and only triggers after successful allocations. It must not attempt to allocate memory from the same arena.

Definition in file arena_hooks.h.

Typedef Documentation

◆ arena_allocation_hook

typedef void(* arena_allocation_hook) (t_arena *arena, int alloc_id, void *ptr, size_t size, size_t offset, size_t wasted, const char *label)

Allocation hook callback type.

Parameters
arenaThe arena from which memory was allocated.
alloc_idA unique ID for this allocation (monotonic counter).
ptrPointer to the newly allocated memory.
sizeSize of the allocation in bytes.
offsetOffset from the start of the arena buffer.
wastedNumber of bytes wasted for alignment.
labelOptional label associated with the allocation.
Examples
/home/toonsa/myProjects/memoryArena/srcs/core/allocation/arena_alloc.c, and /home/toonsa/myProjects/memoryArena/srcs/core/arena_hooks.c.

Definition at line 58 of file arena_hooks.h.

◆ t_arena

typedef struct s_arena t_arena

Forward declaration of arena structure.

Definition at line 45 of file arena_hooks.h.

◆ t_arena_hooks

typedef struct s_arena_hooks t_arena_hooks

Internal structure for managing arena hooks.

This structure stores the current allocation hook and an optional user-defined context that can be used inside the hook.