Does malloc() use brk() or mmap()?

后端 未结 3 1805
一生所求
一生所求 2020-12-05 07:19

c code:

// program break mechanism
// TLPI exercise 7-1

#include 
#include 

void program_break_test() {
    printf(\"%10p\\n         


        
3条回答
  •  悲哀的现实
    2020-12-05 07:59

    If you use malloc in your code, it will call brk() at the beginning, allocated 0x21000 bytes from the heap, that's the address you printed, so the Question 1: the following mallocs requirements can be meet from the pre-allocated space, so these mallocs actually did't call brk, it is a optimization in malloc. If next time you want to malloc size beyond that boundary, a new brk will be called (if not large than the mmap threshold).

提交回复
热议问题