malloc begin
This commit is contained in:
parent
d74a637ebb
commit
7b7db9ff93
2 changed files with 29 additions and 5 deletions
|
@ -1,10 +1,20 @@
|
||||||
#ifndef FT_MALLOC_H
|
#ifndef FT_MALLOC_H
|
||||||
# define FT_MALLOC_H
|
# define FT_MALLOC_H
|
||||||
|
|
||||||
# include <stdlib.h>
|
# include <stddef.h>
|
||||||
|
# include <stdint.h>
|
||||||
|
|
||||||
void free(void *ptr);
|
typedef struct s_header
|
||||||
void *malloc(size_t size);
|
{
|
||||||
void *realloc(void *ptr, size_t size);
|
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
|
#endif
|
||||||
|
|
16
src/malloc.c
16
src/malloc.c
|
@ -1,7 +1,21 @@
|
||||||
#include "ft_malloc.h"
|
#include "ft_malloc.h"
|
||||||
|
|
||||||
void *malloc(size_t size)
|
t_header *morecore(size_t size)
|
||||||
{
|
{
|
||||||
(void)size;
|
(void)size;
|
||||||
return NULL;
|
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