sbrk

How does sbrk() work in C++?

我与影子孤独终老i 提交于 2019-11-27 14:21:48
问题 Where can I read about sbrk() in some detail? How does it exactly work? In what situations would I want to use sbrk() instead of the cumbersome malloc() and new() ? btw, what is the expansion for sbrk() ? 回答1: Have a look at the specification for brk/sbrk. The call basically asks the OS to allocate some more memory for the application by incrementing the previous "break value" by a certain amount. This amount (the first parameter) is the amount of extra memory your application then gets. Most

How are sbrk/brk implemented in Linux?

守給你的承諾、 提交于 2019-11-27 00:37:51
问题 I was thinking about how the Linux kernel implements system calls and I was wondering if someone could give me a high level view of how sbrk/brk work? I've reviewed the kernel code, but there is just so much of it and I don't understand it. I was hoping for a summary from someone? 回答1: In a very high level view, the Linux kernel tracks the memory visible to a process as several "memory areas" ( struct vm_area_struct ). There is also a structure which represents (again in a very high level

Why does calling sbrk(0) twice give a different value?

ぐ巨炮叔叔 提交于 2019-11-26 23:27:35
问题 I'm trying to understand the sbrk() function. From what I know: sbrk(0) returns the current address of the break and doesn't increment it. sbrk(size) increments the address of the break by size bytes and returns the previous address of the break. So I created something to test it: #include <unistd.h> #include <stdio.h> int main(void) { printf("sbrk(0) = %p\n", sbrk(0)); // should return value x printf("sbrk(0) = %p\n", sbrk(0)); // should return value x printf("sbrk(5) = %p\n", sbrk(5)); //

How is malloc() implemented internally? [duplicate]

北慕城南 提交于 2019-11-26 11:59:31
This question already has an answer here: How do malloc() and free() work? 13 answers Can anyone explain how malloc() works internally? I have sometimes done strace program and I see a lot of sbrk system calls, doing man sbrk talks about it being used in malloc() but not much more. DarkDust The sbrk system call moves the "border" of the data segment. This means it moves a border of an area in which a program may read/write data (letting it grow or shrink, although AFAIK no malloc really gives memory segments back to the kernel with that method). Aside from that, there's also mmap which is used

How is malloc() implemented internally? [duplicate]

╄→гoц情女王★ 提交于 2019-11-26 02:39:36
问题 This question already has answers here : How do malloc() and free() work? (13 answers) Closed 6 years ago . Can anyone explain how malloc() works internally? I have sometimes done strace program and I see a lot of sbrk system calls, doing man sbrk talks about it being used in malloc() but not much more. 回答1: The sbrk system call moves the "border" of the data segment. This means it moves a border of an area in which a program may read/write data (letting it grow or shrink, although AFAIK no