Mail Archives: djgpp/1997/11/08/15:34:14
At 12:28 11/7/1997, sl wrote:
>Hi,
>
> The documention on brk() is very brief and I am unable to understand
>what it does and what it is used for. Please email me some sort of extended
>description at "sl AT usemail DOT com". Thank you!
brk() sets your program's "break point". This is the first address which
will cause a fault (SIGSEGV) if you access it. So basically, it sets the top
of your program's address space. It's one of the basic routines to grab
yourself more memory. However, a more common and much more easy to use
variant is sbrk(). You pass it an `int', and it adjusts your break point by
that much, and returns the previous break point. Thus, `sbrk(1000)'
increases your data space by 1000 bytes and returns a pointer to the 1000
new bytes. You usually wouldn't use brk() or sbrk() directly in your
program, since malloc() is so much more convenient, and can free(). malloc()
does use sbrk() inside, however; you could look at its source to learn more.
(Btw, don't confuse "break point" with the "breakpoints" used in debugging.
There may be a better term for the top of the address space, but I don't
know it.)
Nate Eldredge
eldredge AT ap DOT net
- Raw text -