For the project i need to make my own malloc/free program. But i really don't know how to start making the functions. The teacher included some what every function should do but i still don't know how to begin. We only had 1 lesson for C so i'm also not that familiar with the language. These are the 2 first function of the program.
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#define HEAP_SIZE 1024
#define BLOCK_SIZE 64
#define NUMBER_OF_BLOCKS ((HEAP_SIZE) / (BLOCK_SIZE))
struct block
{
uint8_t *address;
uint32_t alloc_count;
struct block *prev;
struct block *next;
};
struct list
{
struct block *first;
struct block *last;
};
/* Initializes the given list to be the empty list.
*
* Preconditions:
* - the given list is a valid pointer to an object of type struct list
*
* This function is already implemented for you.
*/
static void list_init(struct list *list)
{
list->first = NULL;
list->last = NULL;
}
/* Returns true when the given block is valid.
*
* This function is already implemented for you.
*/
static bool block_is_valid(const struct block *block)
{
}
if anyone could provide me some more tips to get me on the right path or even a answer and explain me a bit so i can do the rest f the program on my own. It would be really helpfull.
EDIT: i may have asked a too vague of a question. So here is to point what i do know: - The uint8/32_t is a type for int that are 8/32 bits in size. - i know what pointers, Ive done the exercises on www.learn-c.org/ since that's the thing that we did in class and also the only thing. so i have a basic understanding of what i learned the that site.
What I'm confused about: - I need to make a empty list. but i'm confused since i can't use malloc unless the teacher means i have to make a normal list. But i'm pretty sure there is no built in list() command in C.