added the mandatory show_alloc_mem, and sorted the zones by increasing address in the linked lists
This commit is contained in:
parent
65447f4a0a
commit
db2b5f27bb
92 changed files with 176 additions and 20 deletions
55
srcs/utils.c
Normal file
55
srcs/utils.c
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* utils.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/13 04:41:06 by thrieg #+# #+# */
|
||||
/* Updated: 2025/12/13 06:00:35 by thrieg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "../includes/ft_malloc.h"
|
||||
#include "../libft/ft_printf/ft_printf.h"
|
||||
|
||||
void print_allocs_zone(t_zone *zone)
|
||||
{
|
||||
ft_printf("%s : %p\n", zone->type == E_TINY ? "TINY" : (zone->type == E_SMALL ? "SMALL" : "LARGE"), zone);
|
||||
|
||||
char *zone_end = (char *)zone + zone->size;
|
||||
t_header *header = (t_header *)(zone + 1);
|
||||
while ((char *)header + sizeof(t_header) <= zone_end)
|
||||
{
|
||||
if (header->occupied)
|
||||
ft_printf("%p - %p : %u bytes\n", (char *)header + sizeof(header), (char *)header + sizeof(header) + header->size, (unsigned int)header->size);
|
||||
header = (t_header *)((char *)(header + 1) + header->size);
|
||||
}
|
||||
}
|
||||
|
||||
static t_zone *min_zone_ptr(t_zone *a, t_zone *b, t_zone *c)
|
||||
{
|
||||
t_zone *m = NULL;
|
||||
|
||||
if (a && (!m || (uintptr_t)a < (uintptr_t)m)) m = a;
|
||||
if (b && (!m || (uintptr_t)b < (uintptr_t)m)) m = b;
|
||||
if (c && (!m || (uintptr_t)c < (uintptr_t)m)) m = c;
|
||||
return m;
|
||||
}
|
||||
|
||||
void show_alloc_mem(void)
|
||||
{
|
||||
t_zone *t = g_state.tiny_zone;
|
||||
t_zone *s = g_state.small_zone;
|
||||
t_zone *l = g_state.large_zone;
|
||||
|
||||
while (t || s || l)
|
||||
{
|
||||
t_zone *m = min_zone_ptr(t, s, l);
|
||||
print_allocs_zone(m);
|
||||
|
||||
if (m == t) t = t->next;
|
||||
else if (m == s) s = s->next;
|
||||
else l = l->next;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue