From 7dfa7eb049eded6812041b6922a945a894c74249 Mon Sep 17 00:00:00 2001 From: tomoron Date: Tue, 3 Dec 2024 19:03:30 +0100 Subject: [PATCH] fix norm and set chunk sizes --- Makefile | 14 ++++--- libft/Makefile | 6 +-- main.c | 19 +++++---- srcs/free.c | 88 +++++++++++++++++++++--------------------- srcs/includes/malloc.h | 19 ++++----- srcs/malloc.c | 65 ++++--------------------------- srcs/malloc_utils.c | 78 +++++++++++++++++++++++++++++++++++++ srcs/realloc.c | 73 ++++++++++++++++++----------------- srcs/show_alloc_mem.c | 45 ++++++++++----------- srcs/utils.c | 20 ++++++++++ 10 files changed, 241 insertions(+), 186 deletions(-) create mode 100644 srcs/malloc_utils.c create mode 100644 srcs/utils.c diff --git a/Makefile b/Makefile index 762b285..0d12a1b 100755 --- a/Makefile +++ b/Makefile @@ -1,12 +1,11 @@ -# **************************************************************************** # -# # +# **************************************************************************** # # # ::: :::::::: # # Makefile :+: :+: :+: # # +:+ +:+ +:+ # # By: tomoron +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/07/28 00:35:01 by tomoron #+# #+# # -# Updated: 2024/12/01 03:02:40 by tomoron ### ########.fr # +# Updated: 2024/12/03 15:25:19 by tomoron ### ########.fr # # # # **************************************************************************** # @@ -17,8 +16,11 @@ NAME := libft_malloc_$(HOSTTYPE).so CC = cc SRCS_NAMES = malloc.c \ + malloc_utils.c\ show_alloc_mem.c\ - free.c + free.c\ + realloc.c\ + utils.c SRCS_DIR = srcs @@ -34,7 +36,7 @@ LFT = libft/libft.a LFT_DIR = libft/ -all: exec #libft_malloc.so +all: libft_malloc.so exec: $(OBJS_DIR) $(OBJS) $(LFT) $(CC) -o a.out $(FLAGS) main.c $(OBJS) $(LFT) @@ -43,7 +45,7 @@ libft_malloc.so: $(NAME) ln -sf $(NAME) libft_malloc.so $(LFT): - $(MAKE) -C $(LFT_DIR) + make -j$(shell nproc) -C $(LFT_DIR) $(NAME): $(OBJS_DIR) $(OBJS) $(LFT) $(CC) -shared -o $(NAME) $(OBJS) $(LFT) diff --git a/libft/Makefile b/libft/Makefile index c620247..1e51d5f 100755 --- a/libft/Makefile +++ b/libft/Makefile @@ -6,7 +6,7 @@ # By: tomoron +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2023/07/28 00:35:01 by tomoron #+# #+# # -# Updated: 2024/11/27 17:45:42 by tomoron ### ########.fr # +# Updated: 2024/12/03 15:26:54 by tomoron ### ########.fr # # # # **************************************************************************** # @@ -74,7 +74,7 @@ all: $(NAME) $(NAME): ft_printf $(OBJS) - make --no-print-directory -C ./ft_printf + $(MAKE) --no-print-directory -C ./ft_printf cp ./ft_printf/libftprintf.a $(NAME) ar rcs $(NAME) $(OBJS) @@ -86,7 +86,7 @@ bonus: $(OBJS) $(OBJS_BONUS) clean: rm -f $(OBJS) $(OBJS_BONUS) - make --no-print-directory -C ./ft_printf fclean + $(MAKE) --no-print-directory -C ./ft_printf fclean fclean: clean rm -f $(NAME) diff --git a/main.c b/main.c index 808dcf5..bbedbf9 100644 --- a/main.c +++ b/main.c @@ -3,15 +3,14 @@ int main(void) { - void *ptr; - - ft_malloc(1013); - printf("%p\n",ft_malloc(100)); - ft_malloc(100); - ptr = ft_malloc(1000); - ft_malloc(100); - ft_malloc(100); - ft_free(ptr); - ft_malloc(123); + int i; + + i = 0; + while(i < 110) + { + malloc(256); + i++; + } show_alloc_mem(); + } diff --git a/srcs/free.c b/srcs/free.c index 9c0f1ae..7f5f27f 100644 --- a/srcs/free.c +++ b/srcs/free.c @@ -6,109 +6,111 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/30 18:46:07 by tomoron #+# #+# */ -/* Updated: 2024/12/02 19:54:00 by tomoron ### ########.fr */ +/* Updated: 2024/12/03 18:59:13 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "includes/malloc.h" -t_mem_chunk *get_alloc_chunk(t_alloc *alloc, t_mem_chunk *first,int is_small) +t_mem_chunk *get_alloc_chunk(t_alloc *alloc, t_mem_chunk *first, int is_small) { - size_t size; + size_t size; - if(is_small) + if (is_small) size = SMALL_CHUNK_SIZE; else size = TINY_CHUNK_SIZE; - while(first) + while (first) { - if((t_ul)alloc >= (t_ul)first && ((t_ul)alloc - (t_ul)(first + 1)) <= size) - return(first); + if ((t_ul)alloc >= (t_ul)first && ((t_ul)alloc - \ + (t_ul)(first + 1)) <= size) + return (first); first = first->next; } - return(0); + return (0); } int get_prev_alloc(t_alloc **alloc, t_alloc **res, t_alloc *cur) { - t_alloc *prev; + t_alloc *prev; *res = 0; - if(cur == *alloc) - return(1); + if (cur == *alloc) + return (1); prev = 0; - while(cur) + while (cur) { - if(cur->next == *alloc) + if (cur->next == *alloc) { *res = cur; - return(1); + return (1); } - if(cur->next > *alloc && cur <= *alloc && ((t_ul)alloc - (t_ul)cur) <= cur->size) + if (cur->next > *alloc && cur <= *alloc && ((t_ul)alloc - \ + (t_ul)cur) <= cur->size) { *alloc = cur; *res = prev; - return(1); + return (1); } prev = cur; cur = cur->next; } - return(0); + return (0); } -int free_prealloc(t_alloc *alloc, t_mem_chunk **main_chunk, int is_small) +static int free_prealloc(t_alloc *alloc, t_mem_chunk **main_chunk, \ + int is_small) { - t_mem_chunk *chunk; - t_alloc *prev; - size_t size; + t_mem_chunk *chunk; + t_alloc *prev; + size_t size; - prev = 0; chunk = get_alloc_chunk(alloc, *main_chunk, is_small); - if(!chunk) - return(0); - if(!get_prev_alloc(&alloc, &prev, chunk->first)) - return(1); + if (!chunk) + return (0); + if (!get_prev_alloc(&alloc, &prev, chunk->first)) + return (1); chunk->space_left -= alloc->size + sizeof(t_alloc); - if(chunk->first == alloc) + if (chunk->first == alloc) chunk->first = alloc->next; - else if(prev) + else if (prev) prev->next = alloc->next; - if(!chunk->first) + if (!chunk->first) { - if(*main_chunk == chunk) + if (*main_chunk == chunk) *main_chunk = chunk->next; - if(is_small) + if (is_small) size = SMALL_CHUNK_SIZE; else size = TINY_CHUNK_SIZE; munmap(chunk, size); } - return(1); + return (1); } -void free_large(t_alloc *alloc) +static void free_large(t_alloc *alloc) { - t_alloc *prev; - - if(!get_prev_alloc(&alloc, &prev, g_allocs.large)) + t_alloc *prev; + + if (!get_prev_alloc(&alloc, &prev, g_allocs.large)) return ; - if(alloc == g_allocs.large) + if (alloc == g_allocs.large) g_allocs.large = alloc->next; - else if(prev) + else if (prev) prev->next = alloc->next; munmap(alloc, alloc->size + sizeof(t_alloc)); } -void free(void *ptr) +void free(void *ptr) { - t_alloc *alloc; + t_alloc *alloc; - if(!ptr) + if (!ptr) return ; alloc = (t_alloc *)ptr - 1; - if(free_prealloc(alloc, &g_allocs.tiny, 0)) + if (free_prealloc(alloc, &g_allocs.tiny, 0)) return ; - if(free_prealloc(alloc, &g_allocs.small, 1)) + if (free_prealloc(alloc, &g_allocs.small, 1)) return ; free_large(alloc); } diff --git a/srcs/includes/malloc.h b/srcs/includes/malloc.h index 7604ac0..aff00f2 100644 --- a/srcs/includes/malloc.h +++ b/srcs/includes/malloc.h @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/26 16:38:01 by tomoron #+# #+# */ -/* Updated: 2024/12/02 20:18:33 by tomoron ### ########.fr */ +/* Updated: 2024/12/03 15:21:41 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,12 +20,11 @@ # define PAGE_SIZE sysconf(_SC_PAGESIZE) +# define TINY_MALLOC 256 +# define SMALL_MALLOC 4096 -# define TINY_MALLOC 1024 -# define SMALL_MALLOC 4096 - -# define TINY_CHUNK_SIZE (((16 + TINY_MALLOC) * 100) + 32) -# define SMALL_CHUNK_SIZE 524288 +# define TINY_CHUNK_SIZE align(((16 + TINY_MALLOC) * 100) + 32, PAGE_SIZE) +# define SMALL_CHUNK_SIZE align(((16 + SMALL_MALLOC) * 100) + 32, PAGE_SIZE) typedef struct s_alloc { @@ -45,15 +44,17 @@ typedef struct s_allocations { t_mem_chunk *tiny; t_mem_chunk *small; - t_alloc *large; + t_alloc *large; } t_allocations; -typedef unsigned long t_ul; +typedef unsigned long t_ul; extern t_allocations g_allocs; +size_t align(size_t nb, size_t align_nb); + void *malloc(size_t size); -void show_alloc_mem(); +void show_alloc_mem(void); void free(void *ptr); void *realloc(void *ptr, size_t size); diff --git a/srcs/malloc.c b/srcs/malloc.c index 4794ae9..35779bb 100644 --- a/srcs/malloc.c +++ b/srcs/malloc.c @@ -6,7 +6,7 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/23 17:19:59 by tomoron #+# #+# */ -/* Updated: 2024/12/02 19:54:00 by tomoron ### ########.fr */ +/* Updated: 2024/12/03 19:01:33 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,6 +17,10 @@ t_allocations g_allocs; +t_alloc *get_suitable_addr_in_chunk(t_mem_chunk *chunk, size_t size); +t_mem_chunk *create_new_chunk(int is_small, t_mem_chunk **chunk, \ + t_mem_chunk *prev); + void *get_memory(size_t size, int no_write) { t_mem_chunk *chunk; @@ -25,8 +29,8 @@ void *get_memory(size_t size, int no_write) -1, 0); if (chunk == MAP_FAILED) return (0); - if(no_write) - return(chunk); + if (no_write) + return (chunk); chunk->space_left = size - sizeof(t_mem_chunk); chunk->next = 0; return (chunk); @@ -52,59 +56,7 @@ t_alloc *reserve_addr(t_alloc *addr, size_t size, t_alloc *prev, return (addr + 1); } -t_alloc *get_suitable_addr_in_chunk(t_mem_chunk *chunk, size_t size) -{ - t_alloc *tmp; - size_t space_left; - size_t free_space; - - tmp = chunk->first; - space_left = chunk->space_left; - if((t_ul)chunk->first - (t_ul)(chunk + 1) >= size + sizeof(t_alloc)) - { - tmp = chunk->first; - chunk->first = reserve_addr((void *)(chunk + 1), size, 0, chunk) - 1; - chunk->first->next = tmp; - return(chunk->first + 1); - } - while (tmp->next) - { - free_space = ((t_ul)tmp->next - (t_ul)tmp) - (tmp->size + sizeof(t_alloc)); - if (free_space >= size + sizeof(t_alloc)) - return (reserve_addr( - (void *)((char *)tmp + tmp->size + sizeof(t_alloc)), - size, tmp, chunk)); - space_left -= free_space; - tmp = tmp->next; - } - if (space_left >= size + sizeof(t_alloc)) - return (reserve_addr( - (t_alloc *)((char *)tmp + tmp->size + sizeof(t_alloc)), - size, tmp, chunk)); - return (0); -} - -t_mem_chunk *create_new_chunk(int is_small, t_mem_chunk **chunk, t_mem_chunk *prev) -{ - t_mem_chunk *new; - size_t mmap_size; - - if (is_small) - mmap_size = SMALL_CHUNK_SIZE; - else - mmap_size = TINY_CHUNK_SIZE; - new = get_memory(mmap_size, 0); - if (!new) - return (0); - new->first = (t_alloc *)(new + 1); - if (prev) - prev->next = new; - if (!*chunk) - *chunk = new; - return (new); -} - -void *pre_allocated(size_t size, t_mem_chunk **chunk, int is_small) +static void *pre_allocated(size_t size, t_mem_chunk **chunk, int is_small) { t_mem_chunk *tmp; t_mem_chunk *prev; @@ -138,7 +90,6 @@ void *malloc(size_t size) return (pre_allocated(size, &(g_allocs.tiny), 0)); else if (size <= SMALL_MALLOC) return (pre_allocated(size, &(g_allocs.small), 1)); - new = get_memory(size + sizeof(t_alloc), 1); if (!new) return (0); diff --git a/srcs/malloc_utils.c b/srcs/malloc_utils.c new file mode 100644 index 0000000..4eee64c --- /dev/null +++ b/srcs/malloc_utils.c @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* malloc_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/03 18:44:32 by tomoron #+# #+# */ +/* Updated: 2024/12/03 19:01:11 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "includes/malloc.h" + +void *get_memory(size_t size, int no_write); +t_alloc *reserve_addr(t_alloc *addr, size_t size, t_alloc *prev, + t_mem_chunk *chunk); + +t_mem_chunk *create_new_chunk(int is_small, t_mem_chunk **chunk, \ + t_mem_chunk *prev) +{ + t_mem_chunk *new; + size_t mmap_size; + + if (is_small) + mmap_size = SMALL_CHUNK_SIZE; + else + mmap_size = TINY_CHUNK_SIZE; + new = get_memory(mmap_size, 0); + if (!new) + return (0); + new->first = (t_alloc *)(new + 1); + if (prev) + prev->next = new; + if (!*chunk) + *chunk = new; + return (new); +} + +static t_alloc *get_suitable_addr_in_chunk_middle_end(size_t space_left, \ + t_alloc *tmp, size_t size, t_mem_chunk *chunk) +{ + size_t free_space; + + while (tmp->next) + { + free_space = ((t_ul)tmp->next - (t_ul)tmp) - \ + (tmp->size + sizeof(t_alloc)); + if (free_space >= size + sizeof(t_alloc)) + return (reserve_addr( + (void *)((char *)tmp + tmp->size + sizeof(t_alloc)), + size, tmp, chunk)); + space_left -= free_space; + tmp = tmp->next; + } + if (space_left >= size + sizeof(t_alloc)) + return (reserve_addr( + (t_alloc *)((char *)tmp + tmp->size + sizeof(t_alloc)), + size, tmp, chunk)); + return (0); +} + +t_alloc *get_suitable_addr_in_chunk(t_mem_chunk *chunk, size_t size) +{ + t_alloc *tmp; + size_t space_lft; + + tmp = chunk->first; + space_lft = chunk->space_left; + if ((t_ul)chunk->first - (t_ul)(chunk + 1) >= size + sizeof(t_alloc)) + { + tmp = chunk->first; + chunk->first = reserve_addr((void *)(chunk + 1), size, 0, chunk) - 1; + chunk->first->next = tmp; + return (chunk->first + 1); + } + return (get_suitable_addr_in_chunk_middle_end(space_lft, tmp, size, chunk)); +} diff --git a/srcs/realloc.c b/srcs/realloc.c index 6117eb7..cc4b5e3 100644 --- a/srcs/realloc.c +++ b/srcs/realloc.c @@ -6,72 +6,73 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/12/02 14:41:22 by tomoron #+# #+# */ -/* Updated: 2024/12/02 19:54:00 by tomoron ### ########.fr */ +/* Updated: 2024/12/03 18:57:50 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "includes/malloc.h" -t_mem_chunk *get_alloc_chunk(t_alloc *alloc, t_mem_chunk *first, size_t size); -int get_prev_alloc(t_alloc **alloc, t_alloc **res, t_alloc *cur); -void *realloc_recreate(t_alloc *alloc, size_t size) +t_mem_chunk *get_alloc_chunk(t_alloc *alloc, t_mem_chunk *first, size_t size); +int get_prev_alloc(t_alloc **alloc, t_alloc **res, t_alloc *cur); + +static void *realloc_recreate(t_alloc *alloc, size_t size) { - void *new; - + void *new; + new = malloc(size); - if(alloc->size < size) + if (alloc->size < size) size = alloc->size; ft_memcpy(new, alloc + 1, size); - free(alloc + 1); - return(new); + free(alloc + 1); + return (new); } -void *realloc_prealloc(t_alloc *alloc, t_mem_chunk *chunk, int is_small, size_t size) +static void *realloc_prealloc(t_alloc *alloc, t_mem_chunk *chunk, \ + int is_small, size_t size) { - t_alloc *prev; + t_alloc *prev; chunk = get_alloc_chunk(alloc, chunk, is_small); - if(!chunk) - return(0); - if(!get_prev_alloc(&alloc, &prev, chunk->first)) - return(0); - if(alloc->size >= size) + if (!chunk) + return (0); + if (!get_prev_alloc(&alloc, &prev, chunk->first)) + return (0); + if (alloc->size >= size) { chunk->space_left += alloc->size - size; alloc->size = size; - return(alloc + 1); + return (alloc + 1); } - if((size > (size_t)TINY_CHUNK_SIZE && is_small == 0) + if ((size > (size_t)TINY_CHUNK_SIZE && is_small == 0) || (size > SMALL_CHUNK_SIZE && is_small == 1) || (t_ul)(alloc->next) - (t_ul)(alloc + 1) < size) - return(realloc_recreate(alloc, size)); + return (realloc_recreate(alloc, size)); chunk->space_left -= size - alloc->size; alloc->size = size; - return(alloc + 1); + return (alloc + 1); } -void *realloc_large(t_alloc *alloc, size_t size) +static void *realloc_large(t_alloc *alloc, size_t size) { - t_alloc *prev; + t_alloc *prev; - if(!get_prev_alloc(&alloc, &prev, g_allocs.large)) - return(0); - return(realloc_recreate(alloc, size)); + if (!get_prev_alloc(&alloc, &prev, g_allocs.large)) + return (0); + return (realloc_recreate(alloc, size)); } -void *realloc(void *ptr, size_t size) +void *realloc(void *ptr, size_t size) { - t_alloc *alloc; + t_alloc *alloc; - if(!ptr) - return(malloc(size)); + if (!ptr) + return (malloc(size)); alloc = (t_alloc *)ptr - 1; ptr = realloc_prealloc(alloc, g_allocs.tiny, 0, size); - if(ptr) - return(ptr); - ptr = realloc_prealloc(alloc, g_allocs.tiny, 1, size); - if(ptr) - return(ptr); - return(realloc_large(alloc, size)); - + if (ptr) + return (ptr); + ptr = realloc_prealloc(alloc, g_allocs.small, 1, size); + if (ptr) + return (ptr); + return (realloc_large(alloc, size)); } diff --git a/srcs/show_alloc_mem.c b/srcs/show_alloc_mem.c index 5b335f2..f88c226 100644 --- a/srcs/show_alloc_mem.c +++ b/srcs/show_alloc_mem.c @@ -6,18 +6,18 @@ /* By: tomoron +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/30 12:19:34 by tomoron #+# #+# */ -/* Updated: 2024/12/02 15:24:45 by tomoron ### ########.fr */ +/* Updated: 2024/12/03 18:50:25 by tomoron ### ########.fr */ /* */ /* ************************************************************************** */ #include "includes/malloc.h" -void put_ulnbr_base(t_ul nbr, char *base) +static void put_ulnbr_base(t_ul nbr, char *base) { - t_ul base_len; + t_ul base_len; base_len = ft_strlen(base); - if(nbr >= base_len) + if (nbr >= base_len) { put_ulnbr_base(nbr / base_len, base); write(1, base + (nbr % base_len), 1); @@ -26,32 +26,33 @@ void put_ulnbr_base(t_ul nbr, char *base) write(1, base + nbr, 1); } -size_t show_allocs(t_alloc *alloc) +static size_t show_allocs(t_alloc *alloc) { - size_t nb_bytes; - + size_t nb_bytes; + nb_bytes = 0; - while(alloc) + while (alloc) { nb_bytes += alloc->size; write(1, "0x", 2); put_ulnbr_base((t_ul)alloc + sizeof(t_alloc), "0123456789ABCDEF"); write(1, " - 0x", 5); - put_ulnbr_base((t_ul)alloc +sizeof(t_alloc) + alloc->size, "0123456789ABCDEF"); + put_ulnbr_base((t_ul)alloc + sizeof(t_alloc) + alloc->size, \ + "0123456789ABCDEF"); write(1, " : ", 3); put_ulnbr_base(alloc->size, "0123456789"); write(1, " bytes\n", 7); alloc = alloc->next; } - return(nb_bytes); + return (nb_bytes); } -size_t show_pre_allocated(char *type, t_mem_chunk *chunk) +static size_t show_pre_allocated(char *type, t_mem_chunk *chunk) { - size_t nb_bytes; + size_t nb_bytes; nb_bytes = 0; - while(chunk) + while (chunk) { write(1, type, ft_strlen(type)); write(1, " : 0x", 5); @@ -60,21 +61,21 @@ size_t show_pre_allocated(char *type, t_mem_chunk *chunk) nb_bytes += show_allocs(chunk->first); chunk = chunk->next; } - return(nb_bytes); + return (nb_bytes); } -size_t show_large() +static size_t show_large(void) { - t_alloc *alloc; - size_t total_size; + t_alloc *alloc; + size_t total_size; alloc = g_allocs.large; total_size = 0; - while(alloc) + while (alloc) { write(1, "LARGE : 0x", 10); put_ulnbr_base((t_ul)alloc, "0123456789ABCDEF"); - write(1,"\n", 1); + write(1, "\n", 1); write(1, "0x", 2); put_ulnbr_base((t_ul)(alloc + 1), "0123456789ABCDEF"); write(1, " - 0x", 5); @@ -85,12 +86,12 @@ size_t show_large() total_size += alloc->size; alloc = alloc->next; } - return(total_size); + return (total_size); } -void show_alloc_mem() +void show_alloc_mem(void) { - size_t total; + size_t total; total = 0; total += show_pre_allocated("TINY", g_allocs.tiny); diff --git a/srcs/utils.c b/srcs/utils.c new file mode 100644 index 0000000..09dd18c --- /dev/null +++ b/srcs/utils.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: tomoron +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/12/03 13:20:54 by tomoron #+# #+# */ +/* Updated: 2024/12/03 13:23:31 by tomoron ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "includes/malloc.h" + +size_t align(size_t nb, size_t align_nb) +{ + if (nb % align_nb) + nb = nb + (align_nb - (nb % align_nb)); + return (nb); +}