Path: utzoo!attcan!ncrcan!ziebmef!stephen From: stephen@ziebmef.uucp (Stephen M. Dunn) Newsgroups: comp.sys.ibm.pc Subject: Re: DOS memory allocation Summary: watch out with TSRs Keywords: fooling with DOS's mind Message-ID: <1989May20.132014.5230@ziebmef.uucp> Date: 20 May 89 17:20:13 GMT References: <8261@phoenix.Princeton.EDU> <670@spudge.UUCP> Reply-To: stephen@ziebmef.UUCP (Stephen M. Dunn) Organization: Ziebmef Public Access Unix, Toronto, Ontario Lines: 50 In article <670@spudge.UUCP> johnm@spudge.UUCP (John Munsch) writes: $DOS versions past 3.0 have the INT 21h function call 58h which sets the DOS $memory allocation strategy. One of the available options for this is to $allocate from the top down. Consult a DOS technical manual for details on $the parameters of the function call. Yes, and it also allows you to tell DOS to use the "best-fit" strategy. But back to the original point - allocating memory from the top down. DON'T DO THIS WITH TSRs! If you do, you'll end up rebooting your machine. Why? Let me explain (DOS gurus can skip the rest of this article) When you first boot your machine, it loads in the boot sector, the BIOS, and the BDOS (well, this is close enough for now). Then, it loads the file COMMAND.COM in an odd way. Part of it (the relocating EXE loader) stays low in memory, just above the rest of the O/S. The rest (the command driver) goes at the top of memory. Then you are free to load and run programs as usual. Each time you return from a program to DOS, the resident part of COMMAND.COM (the part in low memory) computes a checksum on where the part in high memory was. If it's okay, it jumps to it. Otherwise, it assumes that the program you just used clobbered it and tries to load COMMAND.COM again into the very top of memory. (The reason it's organized like this is that only the largest programs will wipe COMMAND.COM out of high memory, so it won't have to be reloaded too often). Now, let us say that you have set the memory allocation strategy to get DOS to put your programs high in memory, and that you have just run a TSR. It will, of course, have wiped out the high-memory part of COMMAND.COM. The low-memory part will notice this and will try to put it back. Now, as I understand it, what will happen is that your TSR will be overwritten and the machine has at least a 99.9% chance of crashing. (the other alternative is that maybe DOS will realize that the memory is unavailable and will crash ... I've never tried it, so I don't know which is the case.) So the moral is: if you're going to tell DOS to put things in high memory, you have two problems: 1. DOS will have to reload the command driver after every program you run (not too bad on a hard drive, but a real pain in the butt if you booted from a floppy) 2. Put any TSRs you want into memory BEFORE switching DOS to "last-fit" allocation. -- ------------------------------------------------------------------------------- ! Stephen M. Dunn stephen@ziebmef.UUCP ! DISCLAIMER: Who'd ever ! ! Take off to the Great White North eh, ya hosehead ! claim such dumb ideas? ! -------------------------------------------------------------------------------