71 lines
2.3 KiB
C
71 lines
2.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* main_bonus.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: thrieg < thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/11/28 17:23:45 by thrieg #+# #+# */
|
|
/* Updated: 2025/12/08 15:52:17 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_ex(false);
|
|
|
|
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_ex(true);
|
|
|
|
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_ex(false);
|
|
|
|
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_ex(false);
|
|
|
|
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_ex(false);
|
|
return (0);
|
|
}
|
|
|
|
// cc -g main_bonus.c -L. -lft_malloc -o test_show
|
|
// export LD_LIBRARY_PATH="$PWD"
|