some tests and create data structures

This commit is contained in:
2024-11-28 20:25:32 +01:00
parent a18b30c0b2
commit f721d2e95d
3 changed files with 94 additions and 5 deletions

View File

@ -6,7 +6,7 @@
# By: tomoron <marvin@42.fr> +#+ +:+ +#+ # # By: tomoron <marvin@42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ # # +#+#+#+#+#+ +#+ #
# Created: 2023/07/28 00:35:01 by tomoron #+# #+# # # Created: 2023/07/28 00:35:01 by tomoron #+# #+# #
# Updated: 2024/11/27 17:41:36 by tomoron ### ########.fr # # Updated: 2024/11/27 18:09:19 by tomoron ### ########.fr #
# # # #
# **************************************************************************** # # **************************************************************************** #
@ -34,6 +34,9 @@ LFT_DIR = libft/
all: libft_malloc.so all: libft_malloc.so
exec: $(OBJS_DIR) $(OBJS) $(LFT)
$(CC) -o a.out $(OBJS) $(LFT)
libft_malloc.so: $(NAME) libft_malloc.so: $(NAME)
ln -sf $(NAME) libft_malloc.so ln -sf $(NAME) libft_malloc.so

View File

@ -6,7 +6,7 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/26 16:38:01 by tomoron #+# #+# */ /* Created: 2024/11/26 16:38:01 by tomoron #+# #+# */
/* Updated: 2024/11/26 20:17:37 by tomoron ### ########.fr */ /* Updated: 2024/11/28 20:16:54 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -18,6 +18,35 @@
# endif # endif
#include <stddef.h> #include <stddef.h>
void *malloc(size_t size); #include <sys/mman.h>
#include <unistd.h>
#define TINY_MALLOC_ALL 16384
#define SMALL_MALLOC_ALL 524288
#define TINY_MALLOC 1024
#define SMALL_MALLOC 4096
typedef struct s_alloc
{
size_t size; //8
struct s_alloc *next; //8
} t_alloc; //size 16
typedef struct s_mem_bloc
{
t_alloc *first_alloc; //8
struct s_mem_bloc *next; //8
} t_mem_bloc; //size 16
typedef struct s_allocations
{
t_mem_bloc *tiny;
t_mem_bloc *small;
t_mem_bloc *large;
} t_allocations;
void *ft_malloc(size_t size);
#endif #endif

View File

@ -6,14 +6,71 @@
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */ /* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/23 17:19:59 by tomoron #+# #+# */ /* Created: 2024/11/23 17:19:59 by tomoron #+# #+# */
/* Updated: 2024/11/26 20:17:08 by tomoron ### ########.fr */ /* Updated: 2024/11/28 20:22:55 by tomoron ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "includes/malloc.h" #include "includes/malloc.h"
#include <stdio.h>
#include <errno.h>
#include <string.h>
void *malloc(size_t size) void *get_memory(size_t size)
{
void *ptr;
t_mem_bloc *bloc_info;
ptr = mmap(0, size, PROT_WRITE | PROT_READ, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
if(ptr == MAP_FAILED)
return(0);
bloc_info = ptr;
bloc_info->first_alloc = 0;
bloc_info->next = 0;
return(ptr);
}
void *allocate_memory(size_t size)
{ {
(void)size; (void)size;
return(0); return(0);
} }
t_mem_bloc *get_mem_bloc(t_mem_bloc **bloc, size_t size)
{
t_mem_bloc *tmp;
}
void *pre_allocated(size_t size, s_mem_bloc **bloc)
{
t_mem_bloc *mem_bloc;
t_alloc new;
mem_bloc = get_mem_bloc(bloc, size)
}
void *ft_malloc(size_t size)
{
static t_allocations allocs;
if(size <= TINY_ALLOC)
return(pre_allocated(size, &allocs->tiny));
else if(size <= SMALL_ALLOC)
return(pre_allocated(size, &allocs->small));
else
return(allocate_memory(size));
return(0);
}
#include <stdlib.h>
int main(void)
{
// void *p1 = malloc(1);
// void *p2 = malloc(1);
// void *p3 = malloc(1);
// (void)p3;
// printf("%ld\n", p2 - p1);
}