previous | start | next

mm_malloc

The initial version of mm_malloc in a very simple approach is:

/*
 * mm_malloc - Allocate a block by incrementing the brk pointer.
 *     Always allocate a block whose size is a multiple of the
      alignment.
 */
void *mm_malloc(size_t size)
{
    int newsize = ALIGN(size + SIZE_T_SIZE);
    void *p = mem_sbrk(newsize);
    if ((int)p < 0)
        return NULL;
    else {
        *(size_t *)p = size;
        return (void *)((char *)p + SIZE_T_SIZE);
    }
}

A correspondingly simple version of mm_free is:

/*
 * mm_free - Freeing a block does nothing.
 */
void mm_free(void *ptr)
{
}


previous | start | next