C Everything
This is a C repository containing a curated set of generic data structures and algorithm.
memory_manager.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #define get_mem(nmemb, size) tag_alloc(nmemb, size, __FILE__, __LINE__)
9 #define free_mem(mem_addr) untag_alloc(mem_addr, __FILE__, __LINE__)
10 #define FREE_MEM untag_alloc
11 
12 typedef struct memory_record
13 {
14  void *mem;
15  size_t nmemb;
16  size_t block_size;
17  char *file;
18  int line;
21 
22 
23 typedef struct mem_mamnager{
28 
29 
30 void mem_init(void);
31 void mem_finit(void);
32 
33 void *tag_alloc(size_t nmemb, size_t size, char *file, int line);
34 void untag_alloc(void *mem_addr, char *file, int line);
35 
36 void mem_alloc_report(void);
37 
struct memory_record t_mem_record
void mem_init(void)
Initailize memory module
struct mem_mamnager t_mem_manager
void * tag_alloc(size_t nmemb, size_t size, char *file, int line)
allocate memory and store in mem list (tagging)
void mem_alloc_report(void)
print report of all the assigned memory
void mem_finit(void)
Close memory module by checking and destroying if any tagged memory
void untag_alloc(void *mem_addr, char *file, int line)
deallocate memory and remove from mem list (untagging)
t_mem_record * mem_record
struct memory_record * next