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
71
main_show_alloc_mem.c
Normal file
71
main_show_alloc_mem.c
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main_show_alloc_mem.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: thrieg <thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/12/13 05:54:30 by thrieg #+# #+# */
|
||||
/* Updated: 2025/12/13 05:55:27 by thrieg ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "includes/ft_malloc_public.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char *a = malloc(10);
|
||||
char *b = malloc(100);
|
||||
int *c = malloc(50 * sizeof(int));
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
a[i] = i;
|
||||
for (int i = 0; i < 100; ++i)
|
||||
b[i] = 0xAA;
|
||||
for (int i = 0; i < 50; ++i)
|
||||
c[i] = i * 2;
|
||||
|
||||
write(1, "\n\n\n\n\nafter first alloc: \n\n\n\n\n", sizeof("\n\n\n\n\nafter first alloc: \n\n\n\n\n") - 1);
|
||||
show_alloc_mem();
|
||||
|
||||
free(a);
|
||||
free(b);
|
||||
free(c);
|
||||
|
||||
write(1, "\n\n\n\n\nafter free: \n\n\n\n\n", sizeof("\n\n\n\n\nafter free: \n\n\n\n\n") - 1);
|
||||
show_alloc_mem();
|
||||
|
||||
a = malloc(20);
|
||||
b = malloc(1000);
|
||||
c = malloc(500 * sizeof(int));
|
||||
|
||||
for (int i = 0; i < 20; ++i)
|
||||
a[i] = i;
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
b[i] = 0xAA;
|
||||
for (int i = 0; i < 500; ++i)
|
||||
c[i] = i * 2;
|
||||
|
||||
write(1, "\n\n\n\n\nafter allocating again: \n\n\n\n\n", sizeof("\n\n\n\n\nafter allocating again: \n\n\n\n\n") - 1);
|
||||
show_alloc_mem();
|
||||
|
||||
a = realloc(a, 420); // move the block
|
||||
c = realloc(c, 504 * sizeof(int)); // expend
|
||||
b = realloc(b, 400); // shrink
|
||||
|
||||
write(1, "\n\n\n\n\nafter realloc: \n\n\n\n\n", sizeof("\n\n\n\n\nafter realloc: \n\n\n\n\n") - 1);
|
||||
show_alloc_mem();
|
||||
|
||||
free(a);
|
||||
free(b);
|
||||
free(c);
|
||||
write(1, "\n\n\n\n\nafter free: \n\n\n\n\n", sizeof("\n\n\n\n\nafter free: \n\n\n\n\n") - 1);
|
||||
show_alloc_mem();
|
||||
return (0);
|
||||
}
|
||||
|
||||
// cc -g main_show_alloc_mem.c -L. -lft_malloc -o test_show
|
||||
// export LD_LIBRARY_PATH="$PWD"
|
||||
Loading…
Add table
Add a link
Reference in a new issue