c - custom malloc implementation using a char array as the memory -
c - custom malloc implementation using a char array as the memory -
i'm bad in c programming. i'm asked next task implement malloc memory allocation library.
declare array of 20000 bytes.
you must implement function malloc(). phone call mymalloc(). signature similar malloc(). should implement myfree() has signature , functionality similar free().
mymalloc() allocates memory mentioned array of 20000 bytes.
all info structures required manage memory must reside within same array.
mymalloc() , myfree() must in file called mymalloc.c. should provide suitable header file mymalloc.h.
can tell me how approach problem. i'm clueless. give thanks in advance.
ok - here starting point - implementation of actual mymalloc
/myfree
functions left do...
file: mymalloc.h
#include <stdlib.h> void * mymalloc(size_t size); void myfree(void * ptr);
file: mymalloc.c
#include "mymalloc.h" #define pool_size 20000 static char pool[pool_size]; void * mymalloc(size_t size) { // tbd } void myfree(void * ptr) { // tbd }
note you're going need suitable info construction manage allocations within memory pool - typically 1 or more linked lists used this, there alternatives.
c memory-management malloc free
Comments
Post a Comment