add show_alloc_mem

This commit is contained in:
Gregory 2019-05-09 23:53:14 +03:00
parent dc112a5b7e
commit ce8b634aeb
4 changed files with 38 additions and 11 deletions

View file

@ -3,10 +3,10 @@
/* ::: :::::::: */
/* show_alloc_mem.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* By: gtertysh <gtertysh@student.unit.ua> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/08 21:45:17 by gtertysh #+# #+# */
/* Updated: 2019/05/08 21:45:41 by gtertysh ### ########.fr */
/* Updated: 2019/05/09 23:46:34 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,10 +15,32 @@
#include "libft.h"
#include "stdio.h"
static void print_addr(void *addr)
{
size_t i;
size_t bit_4;
size_t count;
count = sizeof(addr) * 2;
i = 0;
while (i < count)
{
bit_4 = ((size_t)addr >> ((count - i - 1) * 4)) & 0xf;
if (bit_4 < 10)
ft_putnbr(bit_4);
else
ft_putchar('A' + bit_4 - 10);
i++;
}
}
static void print_size(void *addr, size_t size)
{
printf("%p - %p : size %zu", addr, addr + size, size);
fflush(stdout);
print_addr(addr + size);
ft_putstr(" - ");
print_addr(addr);
ft_putstr(" : size ");
ft_putnbr(size);
}
static void print_arena(t_arena *arena)
@ -30,14 +52,17 @@ static void print_arena(t_arena *arena)
else
ft_putstr("LARGE : ");
print_size(arena, arena->size);
ft_putstr("\n");
ft_putstr(" of ARENA\n");
}
static void print_chunk(t_chunk *chunk)
{
ft_putstr(" ");
print_size(chunk, chunk->size);
ft_putstr("\n");
if (chunk->is_free)
ft_putstr(" of free block\n");
else
ft_putstr(" of not free block\n");
}
void show_alloc_mem(void)

View file

@ -10,6 +10,7 @@
#include <errno.h>
#include <zlib.h>
#include "ft_malloc.h"
struct item {
void *ptr;
@ -105,7 +106,7 @@ int main(int argc, const char *const argv[]) {
}
}
/* show_alloc_mem(); */
show_alloc_mem();
}
close(dev_urandom_fd);

View file

@ -6,7 +6,7 @@
/* By: gtertysh <gtertysh@student.unit.ua> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/05/06 22:35:37 by foton #+# #+# */
/* Updated: 2019/05/08 19:47:45 by gtertysh ### ########.fr */
/* Updated: 2019/05/09 23:49:52 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
@ -98,9 +98,10 @@ int realloc_return_same_pointer(void)
t_chunk *new_ptr;
g_base.next = &g_base;
ptr = malloc(20);
new_ptr = realloc(ptr, 10);
ptr = malloc(20000);
new_ptr = realloc(ptr, 100);
_IS(ptr == new_ptr);
// show_alloc_mem();
_END("realloc_return_same_pointer");
}

View file

@ -27,4 +27,4 @@ malloc_fuzzy_fast = executable(
test('basic', malloc_tests)
test('fuzzy', malloc_fuzzy, args: ['10', '1000', '0', '10000'])
test('fuzzy_fast', malloc_fuzzy_fast, args: ['100', '1000', '0', '10000'])
test('fuzzy_fast', malloc_fuzzy_fast, args: ['10', '1000', '0', '10000'])