From: "Bruce Hoyt" Newsgroups: comp.os.msdos.djgpp Subject: Linear addressing using brk() and sbrk() Lines: 43 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2014.211 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211 Message-ID: Date: Sat, 26 Jun 1999 15:58:43 +1200 NNTP-Posting-Host: 203.97.51.158 X-Trace: news.clear.net.nz 930369738 203.97.51.158 (Sat, 26 Jun 1999 16:02:18 NZST) NNTP-Posting-Date: Sat, 26 Jun 1999 16:02:18 NZST To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com I am writing a loader for a Forth interpreter. The loader will provide the system functions I need (memory allocation, file handling, console operations, etc.). The loader will read a binary image containing the Forth interpreter and hand control over to it. I desire this loader to be as portable as possible therefore I am using GCC (DJGPP) and so hope to be able to port my Forth interpreter easily between Linux, Win98, DOS, and possibly other systems. I want to be able to specify a fixed memory location at which I will place the binary image so that the Forth's internal addressing can be done with absolute (linear) addresses. I know this can be done using DPMI virtual addressing. It can also be done in Linux and Win98 using specific system calls. Question 1: Is there a way to do it using malloc? I think not. Question 2: Is there a way to place a separate heap at a fixed (linear) address using brk or sbrk? 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; } And what happens when I malloc some more memory? How do I keep the heap from overlapping desired_address ? Thanks for any help. Bruce Hoyt