memory_arena
Loading...
Searching...
No Matches
arena_visualizer.h
Go to the documentation of this file.
1#ifndef ARENA_VISUALIZER_H
2#define ARENA_VISUALIZER_H
3
4#include <pthread.h>
5#include <stdatomic.h>
6#include <stdbool.h>
7
8#include "arena.h"
9#include "arena_hooks.h"
10
11#define MAX_HISTORY 200
12#define MAX_LABEL_LEN 128
13
14#ifdef __cplusplus
15extern "C"
16{
17#endif
18
19 struct notcurses;
20 struct ncplane;
21
25 typedef struct s_arena_history_entry
26 {
27 bool is_sub;
28 bool is_step;
30 size_t usage;
31 size_t size;
32 size_t offset;
35
39 typedef struct s_arena_visualizer
40 {
42 pthread_mutex_t lock;
43
44 struct notcurses* nc;
45 struct ncplane* main_plane;
46
48 atomic_size_t history_index;
49 atomic_size_t history_count;
50
51 // scrolling offset for ring buffer events
53 // if the user wants to skip the scenario script
56
62 void arena_visualizer_allocation_hook(t_arena* arena, int id, void* ptr, size_t size, size_t offset, size_t wasted,
63 const char* label);
64
65 void arena_visualizer_error_callback(const char* msg, void* context);
66 void step_message(t_arena_visualizer* vis, const char* msg);
67
70
77
78#ifdef __cplusplus
79}
80#endif
81
82#endif // ARENA_VISUALIZER_H
Core public API for the Arena memory allocator.
Allocation hook system for arena-based memory tracking and introspection.
#define MAX_LABEL_LEN
void arena_visualizer_error_callback(const char *msg, void *context)
void step_message(t_arena_visualizer *vis, const char *msg)
t_arena_history_entry history[MAX_HISTORY]
int wait_for_key(t_arena_visualizer *vis)
function that blocks reading keystrokes:
struct ncplane * main_plane
struct s_arena_history_entry t_arena_history_entry
Each ring-buffer event: error, step, normal or sub-alloc.
struct notcurses * nc
void arena_start_interactive_visualizer(t_arena_visualizer *vis, t_arena *arena)
Start the interactive session (blocks until user quits).
void arena_visualizer_enable_history_hook(t_arena_visualizer *vis, t_arena *arena)
Attach our allocation hook to an arena.
pthread_mutex_t lock
#define MAX_HISTORY
atomic_size_t history_index
atomic_size_t history_count
void draw_visualizer(t_arena_visualizer *vis)
char label[MAX_LABEL_LEN]
struct s_arena_visualizer t_arena_visualizer
The main interactive visualizer.
void arena_visualizer_allocation_hook(t_arena *arena, int id, void *ptr, size_t size, size_t offset, size_t wasted, const char *label)
The ring buffer hooks.
Each ring-buffer event: error, step, normal or sub-alloc.
The main interactive visualizer.
The main memory arena structure used for fast allocation.