gpt4 book ai didi

c - brk 和 sbrk 的区别

转载 作者:太空狗 更新时间:2023-10-29 15:15:51 24 4
gpt4 key购买 nike

我是新手,任何人都可以通过一个简短的例子说出 brksbrk 之间的确切区别吗?有没有效率因素可以从两者中选择任何一个?mallocnew 内部调用 brksbrk

最佳答案

int brk(void *addr);

brk() sets the end of the data segment to the value specified by addr, when that value is reasonable, the system has enough memory, and the process does not exceed its maximum data size.

On success, brk() returns zero. On error, -1 is returned, and errno is set to ENOMEM.

void *sbrk(intptr_t increment);

sbrk() increments the program's data space by increment bytes. Calling sbrk() with an increment of 0 can be used to find the current location of the program break.

On success, sbrk() returns the previous program break. (If the break was increased, then this value is a pointer to the start of the newly allocated memory). On error, (void *) -1 is returned, and errno is set to ENOMEM.

From linux manual page

关于c - brk 和 sbrk 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37359498/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com