2019-05-07 22:50:31 +03:00
|
|
|
/* ************************************************************************** */
|
|
|
|
/* */
|
|
|
|
/* ::: :::::::: */
|
|
|
|
/* ft_malloc_internal.h :+: :+: :+: */
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
/* By: gtertysh <gtertysh@student.unit.ua> +#+ +:+ +#+ */
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
/* Created: 2019/05/06 22:37:07 by foton #+# #+# */
|
2019-05-08 19:50:07 +03:00
|
|
|
/* Updated: 2019/05/08 19:45:18 by gtertysh ### ########.fr */
|
2019-05-07 22:50:31 +03:00
|
|
|
/* */
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
2019-05-04 20:23:32 +03:00
|
|
|
#ifndef FT_MALLOC_INTERNAL_H
|
|
|
|
# define FT_MALLOC_INTERNAL_H
|
|
|
|
|
|
|
|
# include <stddef.h>
|
|
|
|
# include <stdint.h>
|
2019-05-08 21:10:37 +03:00
|
|
|
# include <pthread.h>
|
|
|
|
|
2019-05-04 20:23:32 +03:00
|
|
|
|
|
|
|
# define TINY 512
|
2019-05-05 23:31:38 +03:00
|
|
|
# define SMALL 4096
|
|
|
|
# define LARGE 4097
|
2019-05-04 20:23:32 +03:00
|
|
|
# define START -1
|
|
|
|
# define MAGIC 0xDEADBEEF
|
|
|
|
# define NALLOC 100
|
|
|
|
|
2019-05-08 21:10:37 +03:00
|
|
|
typedef struct s_chunk
|
2019-05-04 20:23:32 +03:00
|
|
|
{
|
2019-05-08 21:10:37 +03:00
|
|
|
uint8_t is_free;
|
|
|
|
size_t size;
|
|
|
|
struct s_chunk *next;
|
|
|
|
struct s_chunk *prev;
|
|
|
|
uint32_t magic;
|
|
|
|
} t_chunk;
|
2019-05-04 20:23:32 +03:00
|
|
|
|
|
|
|
# define CHUNK_SIZE(size) ((size) + sizeof(t_chunk))
|
|
|
|
|
2019-05-08 21:10:37 +03:00
|
|
|
typedef struct s_arena
|
2019-05-04 20:23:32 +03:00
|
|
|
{
|
2019-05-08 21:10:37 +03:00
|
|
|
int type;
|
|
|
|
size_t size;
|
|
|
|
struct s_arena *next;
|
|
|
|
t_chunk *heap;
|
|
|
|
} t_arena;
|
2019-05-04 20:23:32 +03:00
|
|
|
|
|
|
|
# define HEAP_SIZE(size) ((size) - sizeof(t_arena))
|
2019-05-05 23:31:38 +03:00
|
|
|
# define ARENA_SIZE(size) ((size) + sizeof(t_arena))
|
2019-05-04 20:23:32 +03:00
|
|
|
|
2019-05-08 21:10:37 +03:00
|
|
|
extern t_arena g_base;
|
|
|
|
|
|
|
|
extern pthread_mutex_t g_malloc_mutex;
|
|
|
|
|
|
|
|
int get_arena_type(size_t size);
|
|
|
|
void *malloc_core(size_t size);
|
|
|
|
void free_core(void *used);
|
2019-05-04 20:23:32 +03:00
|
|
|
|
2019-05-08 19:50:07 +03:00
|
|
|
#endif
|