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

@ -6,21 +6,14 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/12/06 14:47:49 by maiboyer #+# #+# */
/* Updated: 2023/12/09 18:14:11 by maiboyer ### ########.fr */
/* Updated: 2024/05/07 12:45:31 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem_alloc.h"
#include <stdlib.h>
#include "me/alloc/alloc.h"
void *mem_alloc(t_usize size)
{
void *out;
size_t i;
i = 0;
out = malloc(size);
while (out && i < size)
((t_u8 *)out)[i++] = 0;
return (out);
return (me_malloc(size));
}

View file

@ -6,20 +6,15 @@
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/06 15:53:21 by maiboyer #+# #+# */
/* Updated: 2023/12/09 18:14:47 by maiboyer ### ########.fr */
/* Updated: 2024/05/07 12:46:04 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem_alloc.h"
#include "me/alloc/alloc.h"
#include "me/mem/mem_alloc_array.h"
#include <stdlib.h>
void *mem_alloc_array(t_usize item_count, t_usize item_size)
{
t_usize multiplied;
multiplied = item_count * item_size;
if (multiplied == 0 || multiplied / item_count != item_size)
return (NULL);
return (mem_alloc(multiplied));
return (me_calloc(item_count, item_size));
}

View file

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* mem_realloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/07 12:46:18 by maiboyer #+# #+# */
/* Updated: 2024/05/07 12:47:12 by maiboyer ### ########.fr */
/* */
/* ************************************************************************** */
#include "me/mem/mem_realloc.h"
#include "me/alloc/alloc.h"
void *mem_realloc(void *ptr, t_usize size)
{
return (me_realloc(ptr, size));
}