How malloc() and sbrk() works in unix?

前端 未结 4 801
别跟我提以往
别跟我提以往 2021-02-13 10:58

I am new to UNIX, and I am studying some of UNIX system calls such as brk(), sbrk(), and so on....

Last day I have read about malloc()

4条回答
  •  囚心锁ツ
    2021-02-13 11:46

    why malloc reduces the number of sbrk() system calls that the program must perform?

    say, if you call malloc() to request 10 bytes memory, the implementation may use sbrk (or other system call like mmap) to request 4K bytes from OS. Then when you call malloc() next time to request another 10 bytes, it doesn't have to issue system call; it may just return some memory allocated by system call of the last time 4K.

提交回复
热议问题