www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/11/08/15:34:14

Date: Sat, 8 Nov 1997 12:32:32 -0800 (PST)
Message-Id: <199711082032.MAA01367@adit.ap.net>
Mime-Version: 1.0
To: "sl" <sl AT usemail DOT com>, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: brk() -- quick question

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019