我试图了解内存在 C 中是如何工作的,所以现在正在尝试这个sbrk
函数。我知道sbrk(0)
应该返回当前的程序中断,即数据段的结束。
所以我尝试sbrk(0)
多次调用,由于某种原因,我得到的第一个值与其他值不同。例如,这个程序
#include <stdio.h>
#include <unistd.h>
int main()
{
void * currpb = sbrk(0);
printf("The current program break is: %p.\n", currpb);
void * newpb = sbrk(0);
printf("The current program break is: %p.\n", newpb);
void *new2pb = sbrk(0);
printf("The current program break is: %p.\n", new2pb);
void *new3pb = sbrk(0);
printf("The current program break is: %p.\n", new3pb);
}
给我以下输出:
The current program break is: 0x18b0000.
The current program break is: 0x18d1000.
The current program break is: 0x18d1000.
The current program break is: 0x18d1000.
不确定为什么第一个值与其他三个值不同,有什么想法吗?