Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!mit-eddie!uw-beaver!fluke!ssc-vax!uvicctr.UVic.ca!sbanner1 From: sbanner1@uvicctr.UVic.ca.UUCP (S. John Banner) Newsgroups: comp.sys.ibm.pc Subject: Re: DOS memory allocation Message-ID: <674@uvicctr.UVic.ca.UUCP> Date: 29 May 89 01:07:20 GMT References: <8261@phoenix.Princeton.EDU> <670@spudge.UUCP> <1989May20.132014.5230@ziebmef.uucp> Reply-To: sbanner1@uvicctr.UVic.ca.UUCP (S. John Banner) Organization: University of Victoria, Victoria B.C. Canada Lines: 46 In article <1989May20.132014.5230@ziebmef.uucp> stephen@ziebmef.UUCP (Stephen M. Dunn) writes: >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) > 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.) This is was a very good explanation of the point, most informative. Unfortunately, it has one little flaw in it. I have written a TSR that I have never had any complaints about, that uses exactly this sort of a strategy. I have this program that needs to leave a chunk of itself available after it has been used. The program is written in C, and the easyest way to prevent memory fragmentation is to put things into High memory, so... The only reason that the problems described here should ever happen, is if you don't properly allocate the memory (I use Dos's memory allocation calls, and have had none of the problems you describe, not even while I was developing the program). The moral to this story is (I think), follow the rules whenever you can, even if you have to break the rules (as TSRs often have to), follow the rules as much as possible. S. John Banner ...!uw-beaver!uvicctr!sol!sbanner1 ...!ubc-vision!uvicctr!sol!sbanner1 ccsjb@uvvm.bitnet (Please avoid this address if possible) sbanner1%sol.uvic.cdn@ubc.csnet sbanner1@sol.UVic.ca