malloc begin

This commit is contained in:
Gregory 2019-04-26 12:55:55 +03:00
parent d74a637ebb
commit 7b7db9ff93
2 changed files with 29 additions and 5 deletions

View file

@ -1,10 +1,20 @@
#ifndef FT_MALLOC_H
# define FT_MALLOC_H
# include <stdlib.h>
# include <stddef.h>
# include <stdint.h>
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

View file

@ -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;
}
}