mfunyu / malloc

Find out the workings behind optimum memory management and recode it, as well as free and realloc.
2 stars 0 forks source link

[fix] large allocation conncetion #42

Closed mfunyu closed 6 months ago

mfunyu commented 7 months ago

===== test3 Edge-Case Test: Nmalloc ===== Error: mmap failed - size 12530991104 malloc 11230 times, total over 140723017700000 bytes ./test/run_test.sh 3 6.59s user 0.14s system 99% cpu 6.759 total



`test3.c` version -> a362220927e31920393f6e9ad9ca198404b95bfa
mfunyu commented 7 months ago
$> time ./test/run_test.sh 3 
run 3
gcc -I includes -I libft -I ft_printf -I . ./test/correction/test3.c -Llibft -lft -Lft_printf -lftprintf libft_malloc_x86_64_Linux.so -o correction

===== test3 Large Test: Nmalloc =====
Error: mmap failed - size 12530991104
malloc 11230 times, total over 140723017700000 bytes
./test/run_test.sh 3  8.36s user 0.19s system 99% cpu 8.598 total

test3.c version -> d84792e73f78318164d7c7824df714893ec0e5b0

mfunyu commented 7 months ago

The list must be doubly linked to avoid loop O(N). However, adding another header bk to a large block creates chaos.

mfunyu commented 7 months ago

With the difficulty of testing, the time reduced until 0.11s

$> time ./test/run_test.sh 3
run 3
gcc -I includes -I libft -I ft_printf -I . ./test/correction/test3.c -Llibft -lft -Lft_printf -lftprintf libft_malloc_x86_64_Linux.so -o correction

===== test3 Large Test: Nmalloc =====
Error: mmap failed - size 12530991104
malloc 11229 times, total over 140710486710000 bytes
./test/run_test.sh 3  0.11s user 0.13s system 93% cpu 0.261 total