Redefining free memory function in C <p>I'm redefining memory functions in C and I wonder if this idea could work as implementation for the free() function:</p> <pre><code> typedef struct _mem_dictionary { void *addr; size_t size; } mem_dictionary; mem_dictionary *dictionary = NULL; //array of memory dictionaries int dictionary_ct = 0; //dictionary struct counter void *malloc(size_t size) { void *return_ptr = (void *) sbrk(size); if (dictionary == NULL) dictionary = (void *) sbrk(1024 * sizeof(mem_dictionary)); dictionary[dictionary_ct].addr = return_ptr; dictionary[dictionary_ct].size = size; dictionary_ct++; printf("malloc(): %p assigned memory\n",return_ptr); return return_ptr; } void free(void *ptr) { size_t i; int flag = 0; for(i = 0; i &lt; dictionary_ct ; i++){ if(dictionary[i].addr == ptr){ dictionary[i].addr=NULL; dictionary[i].size = 0; flag = 1; break; } } if(!flag){ printf("Remember to free!\n"); } } </code></pre> <p>Thanks in advance!</p>