9.20

    using malloc lib code from csapp site

    • implicit idle list
    • allocated block with header & footer
    • idle block with header & footer
    • no GC
    • first fit strategy

    another modification to malloc lib file

    mm.h

    1. !INCLUDE "./code/malloc/mm.h.diff"

    memlib.c

    1. !INCLUDE "./code/malloc/memlib.c.diff"

    main.c file measure malloc performance

    1. !INCLUDE "./code/malloc/main.c"

    run make to generate both origin main executable file and custom version(using
    -DCUS_MALLOC)

    1. !INCLUDE "./code/malloc/makefile"

    measurement

    1. (cd chapter9/code/malloc; make measure)
    2. time ./origin.main
    3. malloc size: 25000000, heap_size: 28311552
    4. 0.00user 0.01system 0:00.01elapsed 100%CPU (0avgtext+0avgdata 19256maxresident)k
    5. 0inputs+0outputs (0major+4547minor)pagefaults 0swaps
    6. time ./custom.main
    7. malloc size: 25000000, heap_size: 31327104
    8. 0.58user 0.00system 0:00.58elapsed 99%CPU (0avgtext+0avgdata 30592maxresident)k
    9. 0inputs+0outputs (0major+7339minor)pagefaults 0swaps