From: ankleand@mtl.mit.edu (Andrew Karanicolas)
Newsgroups: comp.os.msdos.misc
Subject: Help with Segmented Memory Architecture and Borland C++ (long)
Date: 21 Jul 92 20:12:48 GMT
Organization: MIT Microsystems Technology Laboratories


Hello,

I've got some questions about memory on a Dell 316SX machine with 8M of
total memory and DOS v5.0.  This question relates to a C program
compiled with the Borland C++ compiler v3.0.

In essence, I want things like 2M arrays; 512K points of long int
data.  Since a long int is 4 bytes on the 386, the total array amounts
to 2M I believe.

Here is the C program:

	#include <stdio.h>
	#include <conio.h>
	#include <dos.h>
	#include <alloc.h>

	main()
	{
	long j;
	long *a;

	a = (long *) farcalloc(524288, sizeof(long));

	printf("hello world\n");

	for(j = 0; j <= 524287; j++)
	  {
	  a[j] = 0;
	  printf("j = %ld\n", j);
	  }

	farfree(a);

	printf("goodbye world\n");

	return 0;
	}

Here is config.sys:

	DEVICE=C:\DOS\SETVER.EXE
	FILES=30
	BUFFERS=30
	BREAK=ON
	DEVICE=C:\DOS\HIMEM.SYS
	DEVICE=C:\DOS\EMM386.EXE 4096
	DEVICE=C:\DOS\ANSI.SYS
	DEVICE=C:\DOS\SMARTDRV.SYS
	SHELL=C:\DOS\COMMAND.COM C:\DOS\ /E:1024 /p
	DOS=HIGH

Here is autoexec.bat:

	@ECHO OFF
	REM SET COMSPEC=C:\DOS\COMMAND.COM
	PATH C:\DOS;C:\WINDOWS;C:\PRINTGL;C:\BIN;C:\BORLANDC\BIN;C:\
	PROMPT $P$G
	SET TEMP=C:\WINDOWS\TEMP
	MOUSE /Y >NUL
	WIN

Here is what the machine reports when mem is issued in DOS:

	    655360 bytes total conventional memory
	    655360 bytes available to MS-DOS
	    582240 largest executable program size

	   4587520 bytes total EMS memory
	   4194304 bytes free EMS memory

	   6553600 bytes total contiguous extended memory
	         0 bytes available contiguous extended memory
	   1929216 bytes available XMS memory
        	   MS-DOS resident in High Memory Area

If it helps, I can supply the output of mem with /debug option.

When the C program is run, it gets up to about j = 12 and then just
hangs :)  A full hardware reset is needed to get out (power cycle).
The program was compiled using the 'large' memory model of Borland
C++ v3.0:

	bcc -ml memtest1.c

I called Borland technical support to see what the deal was.  The
interesting thing was that the person I spoke to said that v3.0 does
not deal with more than 640K to 1M of memory.  To use more, a 
"DOS Extender" is needed.  Apparently, several companies are in
business of providing these things; Borland is not one of them.  I got
a phone number for a company called Phar-Lap and I am waiting for a
call back.  Another company called Toolmaker, another called Ergo
but no phone number for Ergo.  

If you were to look in the v3.0 manual "Programmer's Guide" pp.
339-365, DOS memory management is dealt with.  The technical support
guy said flat out that the table is wrong on p. 349 indicating code
size vs. data size for the various memory models.  This table shows
that the large memory model can handle up to 16M of data and 16M of
program.  How could Borland print such an egregious error?  The
technical support guy claims that 1M is basically the limit of Borland
as it stands.

Still with me :)  Do I _need_ this DOS extender?  Can you recommend a
company to get one from?  I'm surprised Borland does not presently
have one though the technical support guy said one is in the works
along with a toolset for OS/2.  I guess I should ask this: How does a C
program that I write know whether to access extended or expanded memory?

I am really learning to dislike segmented memory on a PC but I am
forced to use it.

Thanks for any help, especially if you have read this far.  Please
send e-mail if you contribute.

-- 
Andrew Karanicolas
MIT Microsystems Technology Laboratory
ankleand@mtl.mit.edu