Newsgroups: comp.os.msdos.programmer Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!pshuang From: pshuang@athena.mit.edu (Ping-Shun Huang) Subject: Re: Help in relocating a program in DOS memory In-Reply-To: crystal@eleazar.dartmouth.edu's message of 21 Jun 91 11:13:20 GMT Message-ID: Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology References: <1991Jun21.111320.3481@dartvax.dartmouth.edu> Date: Sun, 23 Jun 91 20:23:53 GMT Lines: 37 In article <1991Jun21.111320.3481@dartvax.dartmouth.edu> crystal@eleazar.dartmouth.edu (Richard Brittain) writes: > I'm trying to make a small (actually tiny model) C program relocate > itself to the top of the 640k memory space in order to prevent fragmentation What kind of fragmentation are you trying to avoid? Are you attempting to make your C program a TSR? > - copy myself from here to there > - deallocate myself > - set all the segment registers equal to the new segment address + 100h One possible reason for your program to be crashing and burning might be that it is an .EXE file. You specified that it is a tiny model C program, but have you used EXE2BIN on it to convert it to a .COM file? If not, what's probably happening is that your program when loaded by DOS, is automatically patched (with information from the .EXE header) so that memory pointer variables are corrected for the memory location your program is now in. In doing a memcpy, you are *NOT* correcting these addresses, even though you are resetting the segment registers. > The better way to do this of course would be for DOS to respect the exe > header blocks saying how much memory a program needs and then allocate only > that much to it - I presume setting last-fit strategy before doing a spawn() > would then achieve what I'm trying to do. I think DOS *DOES* respect the .EXE header information in how much memory should be allocated to a program. However, the last-fit strategy does *NOT* include taking the last-fit block, in this case most likely all the space between memory already used by DOS and TSR's and the 640Kb boundary (and is probably bigger than what your program wants/needs), and chopping it into pieces just because your program asked for less space than is in that block. -- Above text where applicable is (c) Copyleft 1991, all rights deserved by: UNIX:/etc/ping instantiated (Ping Huang) [INTERNET: pshuang@athena.mit.edu]