加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

brk和sbrk之间的区别

发布时间:2020-12-16 10:02:48 所属栏目:百科 来源:网络整理
导读:我是新来的,能用一个简单的例子告诉brk和sbrk之间的确切区别吗?是否有任何效率因素可供选择? malloc和new内部调用brk或sbrk. 解决方法 int brk(void *addr); brk() sets the end of the data segment to the value specified by addr,when that value is r
我是新来的,能用一个简单的例子告诉brk和sbrk之间的确切区别吗?是否有任何效率因素可供选择?
malloc和new内部调用brk或sbrk.

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读