copy on git
This commit is contained in:
commit
42653de246
205 changed files with 7459 additions and 0 deletions
69
includes/ft_malloc.h
Normal file
69
includes/ft_malloc.h
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_malloc.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: thrieg < thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/17 15:06:51 by thrieg #+# #+# */
|
||||
/* Updated: 2025/11/28 17:24:33 by thrieg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_MALLOC_H
|
||||
#define FT_MALLOC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <pthread.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
#include <stddef.h>
|
||||
#include "../libft/ft_hashmap.h"
|
||||
#include "../libft/ft_vector.h"
|
||||
#include "ft_malloc_public.h"
|
||||
|
||||
#define TINY_SIZE_MAX 64
|
||||
#define SMALL_SIZE_MAX 4096
|
||||
#define ALLIGN_BYTES _Alignof(max_align_t)
|
||||
|
||||
typedef enum e_type
|
||||
{
|
||||
E_TINY,
|
||||
E_SMALL,
|
||||
E_LARGE
|
||||
} t_type;
|
||||
|
||||
typedef struct s_zone
|
||||
{
|
||||
t_type type;
|
||||
size_t size;
|
||||
struct s_zone *next; // lock g_mut
|
||||
struct s_zone *prev; // lock g_mut
|
||||
} t_zone;
|
||||
|
||||
typedef struct s_header
|
||||
{
|
||||
size_t size; // lock zone_mut
|
||||
bool occupied; // lock zone_mut
|
||||
t_zone *zone;
|
||||
char padding[8];
|
||||
} t_header;
|
||||
|
||||
typedef struct s_state
|
||||
{
|
||||
t_zone *tiny_zone; // lock g_mut
|
||||
t_zone *small_zone; // lock g_mut
|
||||
t_zone *large_zone; // lock g_mut, 1 zone per alloc for large
|
||||
} t_state;
|
||||
|
||||
extern t_state g_state;
|
||||
extern pthread_mutex_t g_mut; // never lock this inside a zone mut, only the opposite
|
||||
|
||||
void *add_large(size_t size);
|
||||
void *add_small(size_t size);
|
||||
void *add_tiny(size_t size);
|
||||
void *add_page(t_type type);
|
||||
|
||||
#endif
|
||||
25
includes/ft_malloc_public.h
Normal file
25
includes/ft_malloc_public.h
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_malloc_public.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: thrieg < thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/11/25 12:31:43 by thrieg #+# #+# */
|
||||
/* Updated: 2025/11/28 18:26:47 by thrieg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_MALLOC_PUBLIC_H
|
||||
#define FT_MALLOC_PUBLIC_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void *malloc(size_t size);
|
||||
void free(void *ptr);
|
||||
void *calloc(size_t nmemb, size_t size);
|
||||
void *realloc(void *ptr, size_t size);
|
||||
void show_alloc_mem_ex(bool hexdump_free_zones);
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue