title: malloc implementation?
body: <p>I'm trying to implement <code>malloc</code> and <code>free</code> for C, and I am not sure how to reuse memory. I currently have a <code>struct</code> that looks like this:</p>
  
  <pre><code>typedef struct _mem_dictionary {
      void *addr;
      size_t size;
      int freed;
  } mem_dictionary;
  </code></pre>
  
  <p>My <code>malloc</code> looks like this:</p>
  
  <pre><code>void *malloc(size_t size) {
      void *return_ptr = sbrk(size);
      if (dictionary == NULL) 
          dictionary = sbrk(1024 * sizeof(mem_dictionary));
  
      dictionary[dictionary_ct].addr = return_ptr;
      dictionary[dictionary_ct].size = size;
      dictionary[dictionary_ct].freed = 1;
      dictionary_ct++;
  
      return return_ptr;
  }
  </code></pre>
  
  <p>When I free memory, I would just mark the address as <code>0</code> (that would indicate that it is free). In my <code>malloc</code>, I would then use a for loop to look for any value in the array to equal <code>0</code> and then allocate memory to that address. I'm kind of confused how to implement this.</p>