Message-ID: <3776881A.E1420D39@unb.ca> From: Endlisnis Organization: Nortel Networks X-Mailer: Mozilla 4.51 [en] (Win98; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: Linear addressing using brk() and sbrk() References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 34 Date: Sun, 27 Jun 1999 20:22:19 GMT NNTP-Posting-Host: 209.226.124.235 X-Trace: news20.bellglobal.com 930514939 209.226.124.235 (Sun, 27 Jun 1999 16:22:19 EDT) NNTP-Posting-Date: Sun, 27 Jun 1999 16:22:19 EDT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Bruce Hoyt wrote: > Question 3: Is it very bad to do the following? > > unsigned desired_address = 0x100000; > unsigned desired_size = 0x80000; > if(sbrk((void *)desired_address - sbrk(0)) == (void *)-1) { > printf("Can't adjust brk to %X\n", desired_address); > return memory_error1; > } > if(sbrk(desired_size) == (void *)-1) { > printf("Can't allocate %X bytes for image\n", > desired_size); > return memory_error2; > } Is it bad... I don't know, but it wastes upwards of 1Meg of RAM. And it wouldn't work if you had already allocated more than 1Meg of RAM for your current program. > And what happens when I malloc some more memory? How do I keep > the heap from overlapping desired_address ? The malloced memory will be AFTER the block you've allocated (it will not overlap). -- (\/) Endlisnis (\/) s257m AT unb DOT ca Endlisnis AT HotMail DOT com ICQ: 32959047