Made a memory allocator (crude)

This commit is contained in:
Maieul BOYER 2024-05-07 15:21:41 +02:00
parent b5c7344851
commit 941bac31b6
No known key found for this signature in database
53 changed files with 469 additions and 146 deletions

View file

@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_arena.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 09:47:50 by maiboyer #+# #+# */
/* Updated: 2024/05/07 14:20:20 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/alloc/alloc.h"
#include "me/alloc/alloc_internal.h"
#include "me/fs/putstr_fd.h"
#include "me/mem/mem_set_zero.h"
#include <stdlib.h>
void *__libc_malloc(size_t size);
t_arena_page *get_head_arena(void)
{
static t_arena_page *val = NULL;
if (val == NULL)
{
if (alloc_arena(&val))
{
me_putstr_fd("Error: malloc failed\n", 2);
exit(1);
}
}
return (val);
}
t_error alloc_arena(t_arena_page **out)
{
if (out == NULL)
return (ERROR);
*out = __libc_malloc(sizeof(**out));
if (*out == NULL)
return (ERROR);
mem_set_zero(*out, sizeof(**out));
return (NO_ERROR);
}