malloc begin
This commit is contained in:
parent
d74a637ebb
commit
7b7db9ff93
2 changed files with 29 additions and 5 deletions
|
@ -1,7 +1,17 @@
|
|||
#ifndef FT_MALLOC_H
|
||||
# define FT_MALLOC_H
|
||||
|
||||
# include <stdlib.h>
|
||||
# include <stddef.h>
|
||||
# include <stdint.h>
|
||||
|
||||
typedef struct s_header
|
||||
{
|
||||
struct s_header *next;
|
||||
size_t size;
|
||||
} t_header;
|
||||
|
||||
static t_header base;
|
||||
static t_header *freep = NULL;
|
||||
|
||||
void free(void *ptr);
|
||||
void *malloc(size_t size);
|
||||
|
|
16
src/malloc.c
16
src/malloc.c
|
@ -1,7 +1,21 @@
|
|||
#include "ft_malloc.h"
|
||||
|
||||
void *malloc(size_t size)
|
||||
t_header *morecore(size_t size)
|
||||
{
|
||||
(void)size;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *malloc(size_t size)
|
||||
{
|
||||
t_header *p;
|
||||
t_header *prevp;
|
||||
size_t nunits;
|
||||
|
||||
nunits = (size + sizeof(t_header) - 1) / (sizeof(t_header) + 1);
|
||||
if ((prevp = freep) == NULL)
|
||||
{
|
||||
base.next = freep = prevp = &base;
|
||||
base.size = 0;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue