Date: Mon, 8 Sep 1997 11:21:59 +0300 (IDT) From: Eli Zaretskii To: *** Brett *** cc: DJGPP Subject: Re: system() and memory In-Reply-To: <199709080314.NAA07619@rabble.uow.edu.au> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Precedence: bulk On Mon, 8 Sep 1997, *** Brett *** wrote: > > > Use spawn command. It frees up _loads_ more memory for your programs. > > > > This is incorrect. `spawn' does NOT release more memory than `system', > > because in most cases `system' just calls `spawn' internally. > > > Is this just for DJGPP, or the way all compilers do it? On DOS, it is compiler-specific. What I said is correct for DJGPP. > I haven't used > system() any more because I wrote a menu program in Borland C++ with Turbo > Vision, and system() calls left you with about 230K free memory, whereas > spawn gave about 500K (in 16-bit DPMI). This means that they've gone to a lot of trouble to swap the parent out of the conventional memory when `spawn' is called, but didn't do that for `system'. > I thought the difference was that spawn loaded and executed the program > directly, whereas system() calls the COMSPEC (command.com) to load the > program or execute the command. COMMAND.COM is too dumb to let it run child programs in an environment that needs long command lines and other features without which you cannot have enough compatibility to Unix to make porting easy. OTOH, the ``features'' provided by COMMAND.COM (pipes and redirection) are so simple to emulate that it doesn't make sense to lose all the niceties DJGPP's `spawn' provides just to avoid a few lines of code that implement pipes and redirection. So our `system' only calls COMMAND.COM when it sees a batch file or an internal command. This allows to throw in a few more sugar, like support for multiple commands separated by a semi-colon, emulation of "cd" that knows about foward slashes and changes drives on the fly, etc. > Could you please clear this up for me? I don't have enough time or hard > drive space to download the DJGPP source yet. You don't need the sources, it is all explained in the libc reference. Type "info libc alpha system" from the DOS prompt and read there. There's much more to this than meets the eye, or than I could describe in a message.