35 lines
1.3 KiB
C
35 lines
1.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_malloc.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: thrieg < thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/11/17 15:02:55 by thrieg #+# #+# */
|
|
/* Updated: 2025/11/25 14:30:44 by thrieg ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "../includes/ft_malloc.h"
|
|
|
|
void *malloc(size_t size)
|
|
{
|
|
pthread_mutex_lock(&g_mut);
|
|
if (!size || size % ALLIGN_BYTES)
|
|
size = ((size / ALLIGN_BYTES) + 1) * ALLIGN_BYTES;
|
|
void *ret = NULL;
|
|
if (size > SMALL_SIZE_MAX)
|
|
{
|
|
ret = add_large(size);
|
|
}
|
|
else if (size > TINY_SIZE_MAX)
|
|
{
|
|
ret = add_small(size);
|
|
}
|
|
else
|
|
{
|
|
ret = add_tiny(size);
|
|
}
|
|
pthread_mutex_unlock(&g_mut);
|
|
return (ret);
|
|
}
|