This is a guide to creating your own Custom Memory Allocator. I have wrote my own general-purpose Custom Memory Allocator in C, inspired by postgres's memory contexts. I've decided to document the process of building this memory allocator for future references.
Let’s answer these questions by understanding the caveats of existing memory models and writing our own memory allocator from scratch in C.
The custom memory allocator can be used like any other shared library.
#include "perfloc.h"
typedef struct custom_type {
int a;
int arr[10];
} custom_type;
int main()
{
MemoryChunk pmc = getPerfMem();
custom_type* type = (custom_type*)perfalloc(pmc, sizeof(custom_type));
type->a = 10;
type->arr[0] = 1;
perffree(pmc, type);
dropPerfMem(pmc);
return 0;
}