fix compilation error on newer clang version, fix some norm errors and start doing show_alloc_mem_ex function
This commit is contained in:
@ -6,13 +6,13 @@
|
||||
/* By: tomoron <tomoron@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/11/30 12:19:34 by tomoron #+# #+# */
|
||||
/* Updated: 2024/12/05 17:05:48 by tomoron ### ########.fr */
|
||||
/* Updated: 2025/02/14 18:18:48 by tomoron ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "includes/malloc.h"
|
||||
|
||||
static void put_ulnbr_base(t_ul nbr, char *base)
|
||||
void put_ulnbr_base(t_ul nbr, char *base)
|
||||
{
|
||||
t_ul base_len;
|
||||
|
||||
@ -26,7 +26,7 @@ static void put_ulnbr_base(t_ul nbr, char *base)
|
||||
write(1, base + nbr, 1);
|
||||
}
|
||||
|
||||
static size_t show_allocs(t_alloc *alloc)
|
||||
static size_t show_allocs(t_alloc *alloc, int dump)
|
||||
{
|
||||
size_t nb_bytes;
|
||||
|
||||
@ -42,12 +42,14 @@ static size_t show_allocs(t_alloc *alloc)
|
||||
write(1, " : ", 3);
|
||||
put_ulnbr_base(alloc->size, "0123456789");
|
||||
write(1, " bytes\n", 7);
|
||||
if(dump)
|
||||
hex_dump((void *)(alloc + 1), alloc->size);
|
||||
alloc = alloc->next;
|
||||
}
|
||||
return (nb_bytes);
|
||||
}
|
||||
|
||||
static size_t show_pre_allocated(char *type, t_mem_chunk *chunk)
|
||||
size_t show_pre_allocated(char *type, t_mem_chunk *chunk, int dump)
|
||||
{
|
||||
size_t nb_bytes;
|
||||
|
||||
@ -58,13 +60,13 @@ static size_t show_pre_allocated(char *type, t_mem_chunk *chunk)
|
||||
write(1, " : 0x", 5);
|
||||
put_ulnbr_base((t_ul)chunk, "0123456789ABCDEF");
|
||||
write(1, "\n", 1);
|
||||
nb_bytes += show_allocs(chunk->first);
|
||||
nb_bytes += show_allocs(chunk->first, dump);
|
||||
chunk = chunk->next;
|
||||
}
|
||||
return (nb_bytes);
|
||||
}
|
||||
|
||||
static size_t show_large(void)
|
||||
size_t show_large(int dump)
|
||||
{
|
||||
t_alloc *alloc;
|
||||
size_t total_size;
|
||||
@ -84,6 +86,8 @@ static size_t show_large(void)
|
||||
put_ulnbr_base(alloc->size, "0123456789");
|
||||
write(1, " bytes\n", 7);
|
||||
total_size += alloc->size;
|
||||
if(dump)
|
||||
hex_dump((void *)(alloc + 1), alloc->size);
|
||||
alloc = alloc->next;
|
||||
}
|
||||
return (total_size);
|
||||
@ -95,9 +99,9 @@ void show_alloc_mem(void)
|
||||
|
||||
total = 0;
|
||||
pthread_mutex_lock(&g_mallock);
|
||||
total += show_pre_allocated("TINY", g_allocs.tiny);
|
||||
total += show_pre_allocated("SMALL", g_allocs.small);
|
||||
total += show_large();
|
||||
total += show_pre_allocated("TINY", g_allocs.tiny, 0);
|
||||
total += show_pre_allocated("SMALL", g_allocs.small, 0);
|
||||
total += show_large(0);
|
||||
pthread_mutex_unlock(&g_mallock);
|
||||
write(1, "Total : ", 8);
|
||||
put_ulnbr_base(total, "0123456789");
|
||||
|
Reference in New Issue
Block a user