add show_alloc_mem with printf

This commit is contained in:
Gregory 2019-05-08 21:46:06 +03:00
parent 3fa3ff5304
commit dc112a5b7e
3 changed files with 65 additions and 1 deletions

View file

@ -31,7 +31,9 @@ sources = [
'src/malloc.c',
'src/free.c',
'src/realloc.c',
'src/get_arena_type.c'
'src/calloc.c',
'src/get_arena_type.c',
'src/show_alloc_mem.c',
]
libft = subproject('libft')

60
src/show_alloc_mem.c Normal file
View file

@ -0,0 +1,60 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* show_alloc_mem.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/08 21:45:17 by gtertysh #+# #+# */
/* Updated: 2019/05/08 21:45:41 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_malloc_internal.h"
#include "ft_malloc.h"
#include "libft.h"
#include "stdio.h"
static void print_size(void *addr, size_t size)
{
printf("%p - %p : size %zu", addr, addr + size, size);
fflush(stdout);
}
static void print_arena(t_arena *arena)
{
if (arena->type == TINY)
ft_putstr("TINY : ");
else if (arena->type == SMALL)
ft_putstr("SMALL : ");
else
ft_putstr("LARGE : ");
print_size(arena, arena->size);
ft_putstr("\n");
}
static void print_chunk(t_chunk *chunk)
{
ft_putstr(" ");
print_size(chunk, chunk->size);
ft_putstr("\n");
}
void show_alloc_mem(void)
{
t_arena *arena_runner;
t_chunk *heap_runner;
arena_runner = g_base.next;
while (arena_runner != &g_base)
{
heap_runner = arena_runner->heap;
print_arena(arena_runner);
while (heap_runner)
{
print_chunk(heap_runner);
heap_runner = heap_runner->next;
}
arena_runner = arena_runner->next;
}
}

View file

@ -35,6 +35,7 @@ int returns_not_null_pointer(void)
_IS(ptr->next == NULL);
_IS(ptr->prev != NULL);
_IS(ptr->prev->size > TINY * NALLOC && ptr->prev->size < SMALL * NALLOC);
// show_alloc_mem();
_END("returns_not_null_pointer");
}
@ -87,6 +88,7 @@ int malloc_creates_new_arena(void)
_IS(g_base.next->next != &g_base);
_IS(g_base.next->type == TINY);
_IS(g_base.next->heap->next == second_arena_chunk - 1);
// show_alloc_mem();
_END("malloc_creates_new_arena");
}