Put the custom allocator in its own lib, as to lessen the difficulty to switch between libc's allocator and a custom one (#7)
This commit is contained in:
parent
713f0f0302
commit
cb7f3c3fdf
85 changed files with 1121 additions and 877 deletions
52
allocator/src/lc_alloc/functions1.c
Normal file
52
allocator/src/lc_alloc/functions1.c
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* functions1.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/14 18:02:12 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:49:50 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "aq/allocator.h"
|
||||
#include "aq/libc_wrapper.h"
|
||||
#include "me/types.h"
|
||||
|
||||
void *__libc_malloc(t_usize size);
|
||||
void *__libc_calloc(t_usize size, t_usize elem);
|
||||
void *__libc_realloc(void *ptr, t_usize size);
|
||||
void *__libc_reallocarray(void *ptr, t_usize size, t_usize elem);
|
||||
void __libc_free(void *ptr);
|
||||
|
||||
void *lc_malloc(t_allocator *self, t_usize size)
|
||||
{
|
||||
(void)(self);
|
||||
return (__libc_malloc(size));
|
||||
}
|
||||
|
||||
void *lc_calloc(t_allocator *self, t_usize size, t_usize elem)
|
||||
{
|
||||
(void)(self);
|
||||
return (__libc_calloc(size, elem));
|
||||
}
|
||||
|
||||
void *lc_realloc(t_allocator *self, void *ptr, t_usize size)
|
||||
{
|
||||
(void)(self);
|
||||
return (__libc_realloc(ptr, size));
|
||||
}
|
||||
|
||||
void *lc_realloc_array(t_allocator *self, void *ptr, t_usize size, t_usize elem)
|
||||
{
|
||||
(void)(self);
|
||||
return (__libc_reallocarray(ptr, size, elem));
|
||||
}
|
||||
|
||||
void lc_free(t_allocator *self, void *ptr)
|
||||
{
|
||||
(void)(self);
|
||||
return (__libc_free(ptr));
|
||||
}
|
||||
|
||||
32
allocator/src/lc_alloc/functions2.c
Normal file
32
allocator/src/lc_alloc/functions2.c
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* functions2.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/14 18:06:34 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:48:41 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "aq/allocator.h"
|
||||
#include "aq/libc_wrapper.h"
|
||||
|
||||
void lc_uninit(t_allocator *self)
|
||||
{
|
||||
(void)(self);
|
||||
}
|
||||
|
||||
t_allocator lc_init(void)
|
||||
{
|
||||
return ((t_allocator){
|
||||
.alloc = lc_malloc,
|
||||
.alloc_array = lc_calloc,
|
||||
.realloc = lc_realloc,
|
||||
.realloc_array = lc_realloc_array,
|
||||
.free = lc_free,
|
||||
.uninit = lc_uninit,
|
||||
.alloc_data = NULL,
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue