标题: 帮忙看看这句话怎么理解( from man page of sbrk ) [打印本页] 作者: bigluo 时间: 2004-02-05 11:27 标题: 帮忙看看这句话怎么理解( from man page of sbrk ) NAME
brk, sbrk - change data segment size
SYNOPSIS
#include <unistd.h>;
int brk(void *end_data_segment);
void *sbrk(ptrdiff_t increment);
DESCRIPTION
brk sets the end of the data segment to the value specified by
end_data_segment, when that value is reasonable, the system does have
enough memory and the process does not exceed its max data size (see
setrlimit(2)).
sbrk increments the program's data space by increment bytes. sbrk
isn't a system call, it is just a C library wrapper. Calling sbrk with
an increment of 0 can be used to find the current location of the pro-
gram break.
RETURN VALUE
On success, brk returns zero, and sbrk returns a pointer to the start
of the new area. On error, -1 is returned, and errno is set to ENOMEM.
其中Calling sbrk with an increment of 0 can be used to find the current location of the program break.
program break应该理解成什么???作者: bigluo 时间: 2004-02-05 12:21 标题: 帮忙看看这句话怎么理解( from man page of sbrk ) 自己up一下作者: homegirl 时间: 2004-02-05 13:21 标题: 帮忙看看这句话怎么理解( from man page of sbrk ) 我觉得整句话因该是“寻找当前的程序断点”作者: bigluo 时间: 2004-02-05 15:19 标题: 帮忙看看这句话怎么理解( from man page of sbrk ) sbrk在linux中是用来改变data segment的尺寸的,这个prog break显然不该理解成为断点吧,data segment和break有什么关系?作者: henngy 时间: 2004-02-05 15:40 标题: 帮忙看看这句话怎么理解( from man page of sbrk ) 拜托先学学数据编程!作者: bigluo 时间: 2004-02-06 09:30 标题: 帮忙看看这句话怎么理解( from man page of sbrk ) 请你来帮我解释一下什么叫数据编程,小生不才,弄了这么多年的unix,真就还没有听说过有个什么数据编程!作者: jianyan 时间: 2004-02-06 13:20 标题: 帮忙看看这句话怎么理解( from man page of sbrk ) 在UNIX/LINUX中,程序运行时动态内存以堆的方式来分配。
对程序而言,它使用的动态内存地址是虚拟内存,
代码用内存和数据用内存,一个从上往下,一个从下往上增长。
在LINUX,X86中,可用虚拟内存为0x00000000--0xffffffff;
对每一个进程都是一个独立的4GB空间。
但前面的1GB是内核用的,后面某一个位置才是程序运行时动态内存堆
的开始地址,你用多少它向上增多少。
我时常使用sbrk(0)来返回我的程式当前使用了多少内存。
main(){
int start,end;
start = sbrk(0);
....
malloc(***);
....
end = sbrk(0);
printf("hello I used %d vmemory",end - start);
}
打字打得累死好像还是没有说明白sbrk,没时间打了。
综上所述,我把楼的的那句话
Calling sbrk with an increment of 0 can be used to find the current location of the program break
理解为使用sbrk(0)可以返回当前的程序所有使用的虚拟内存 达到/越过 了的地址。
break = 超过;超越作者: forest077 时间: 2004-02-07 23:49 标题: 帮忙看看这句话怎么理解( from man page of sbrk ) 从字面理解,整段话的意思应该是:
sbrk把程序的数据段增加increment个字节。sbrk不是一个系统调用,而是一个C的库函数。用increment为0来调用sbrk函数,可以返回程序当前所停留的数据段位置。
jianyan的程序两个sbrk返回值相减得出占用内存情况,应该就是前后两个调用时,数据段当前指针相减,所以得出内存占用的大小。