Allocator V1.0
* Allocator Version 1.0
This commit is contained in:
parent
04691819f7
commit
5d2202a0c9
20 changed files with 609 additions and 74 deletions
|
|
@ -6,15 +6,13 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/12 22:20:30 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 16:17:25 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/17 15:34:26 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef INTERNAL_VG_FUNCS_H
|
||||
#define INTERNAL_VG_FUNCS_H
|
||||
|
||||
#include "aq/alloc_internal.h"
|
||||
|
||||
#include "me/types.h"
|
||||
#if !defined(NVALGRIND) || defined(VGHEADER)
|
||||
# ifdef NVALGRIND
|
||||
|
|
@ -30,7 +28,7 @@
|
|||
|
||||
static inline t_usize redzone_size(void)
|
||||
{
|
||||
return (sizeof(t_mblock));
|
||||
return (8);
|
||||
}
|
||||
|
||||
#ifdef VGFUNCS
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/14 17:54:03 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/14 18:08:16 by maiboyer ### ########.fr */
|
||||
/* Updated: 2024/05/16 15:43:00 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -23,4 +23,6 @@ void *m_realloc_array(t_allocator *self, void *ptr, t_usize size,
|
|||
void m_free(t_allocator *self, void *ptr);
|
||||
void m_uninit(t_allocator *self);
|
||||
|
||||
t_allocator m_init(void);
|
||||
|
||||
#endif /* MELLOC_H */
|
||||
|
|
|
|||
64
allocator/include/aq/melloc_interal.h
Normal file
64
allocator/include/aq/melloc_interal.h
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* melloc_interal.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: maiboyer <maiboyer@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/05/15 15:27:46 by maiboyer #+# #+# */
|
||||
/* Updated: 2024/05/16 14:58:27 by maiboyer ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef MELLOC_INTERAL_H
|
||||
#define MELLOC_INTERAL_H
|
||||
|
||||
#include "aq/allocator.h"
|
||||
#include "me/types.h"
|
||||
|
||||
#define PAGE_LIST_MAX 255
|
||||
#define PAGE_POW_2 12
|
||||
#define PAGE_ALIGN 3
|
||||
|
||||
typedef struct s_chunk
|
||||
{
|
||||
bool used : 1;
|
||||
t_u64 size : 63;
|
||||
} t_chunk;
|
||||
|
||||
typedef struct s_page
|
||||
{
|
||||
t_usize size;
|
||||
void *data;
|
||||
} t_page;
|
||||
|
||||
typedef struct s_page_list
|
||||
{
|
||||
t_usize len;
|
||||
t_page pages[PAGE_LIST_MAX];
|
||||
struct s_page_list *next;
|
||||
} t_page_list;
|
||||
|
||||
struct s_allocator_melloc
|
||||
{
|
||||
t_allocator_alloc alloc;
|
||||
t_allocator_alloc_array alloc_array;
|
||||
t_allocator_realloc realloc;
|
||||
t_allocator_realloc_array realloc_array;
|
||||
t_allocator_free free;
|
||||
t_allocator_uninit uninit;
|
||||
t_page_list *list;
|
||||
};
|
||||
|
||||
t_error alloc_page_list(t_page_list **out);
|
||||
|
||||
void *m_malloc(struct s_allocator_melloc *self, t_usize size);
|
||||
void *m_alloc_array(struct s_allocator_melloc *self, t_usize size,
|
||||
t_usize count);
|
||||
void *m_realloc(struct s_allocator_melloc *self, void *ptr, t_usize min_size);
|
||||
void *m_realloc_array(struct s_allocator_melloc *self, void *ptr, t_usize size,
|
||||
t_usize count);
|
||||
void m_free(struct s_allocator_melloc *self, void *ptr);
|
||||
void m_uninit(struct s_allocator_melloc *self);
|
||||
|
||||
#endif /* MELLOC_INTERAL_H */
|
||||
Loading…
Add table
Add a link
Reference in a new issue