From 7b7db9ff933823846c622bf70434fee288d16724 Mon Sep 17 00:00:00 2001 From: Gregory Date: Fri, 26 Apr 2019 12:55:55 +0300 Subject: [PATCH] malloc begin --- inc/ft_malloc.h | 18 ++++++++++++++---- src/malloc.c | 16 +++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/inc/ft_malloc.h b/inc/ft_malloc.h index 1f79f56..8ce0f66 100644 --- a/inc/ft_malloc.h +++ b/inc/ft_malloc.h @@ -1,10 +1,20 @@ #ifndef FT_MALLOC_H # define FT_MALLOC_H -# include +# include +# include -void free(void *ptr); -void *malloc(size_t size); -void *realloc(void *ptr, size_t size); +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); +void *realloc(void *ptr, size_t size); #endif diff --git a/src/malloc.c b/src/malloc.c index 985eb66..744040d 100644 --- a/src/malloc.c +++ b/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; + } } \ No newline at end of file