How to create a custom memory allocator?

I want all the bufs flowing in the pipeline to be created using this memory allocation.

I have already created :

int dma_buf_alloc(const char *path, size_t size, int *fd, void **va);
void dma_buf_free(size_t size, int *fd, void *va);

Perhaps you could consider the approach of “LD_PRELOAD” if your environment is Linux.

Use LD_PRELOAD to load your library before the standard C library (libc), allowing your functions to take precedence.