Message-Id: <200007141442.RAA00799@mailgw1.netvision.net.il> Date: Fri, 14 Jul 2000 17:42:36 +0200 To: "David Lee" X-Mailer: Emacs 20.6 (via feedmail 8.2.emacs20_6 I) and Blat ver 1.8.5b From: "Eli Zaretskii" CC: djgpp AT delorie DOT com In-reply-to: <8kn0ac$64c1@imsp212.netvigator.com> (keeyu@poetic.com) Subject: Re: DOS Memory Cleanup References: <8kn0ac$64c1 AT imsp212 DOT netvigator DOT com> Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > From: "David Lee" > Newsgroups: comp.os.msdos.djgpp > Date: Fri, 14 Jul 2000 20:16:18 +0800 > > If my program allocates DOS memory via __dpmi_allocate_dos_memory(), do I > have to free it via __dpmi_free_dos_memory() before my programs exits? In general, no, you don't (but see below). The memory will be released by DOS, like any DOS memory is at program's exit. > Would the DPMI host 'clean up the mess' for me? DOS memory is not allocated and freed by the DPMI host, it is allocated and freed by DOS. The DPMI host simply calls DOS, and in addition creates a selector for the buffer you allocated. Note that some of the DPMI hosts has bugs in releasing resources in nested DPMI programs. With those buggy hosts, you risk leaking selectors (those very selectors allocated to allow access to the DOS buffer from protected mode) if you don't free DOS memory yourself. For these reasons, I recommend to allocate and free DOS memory directly, by calling functions 48h, 49h, and 50h of Int 21h via __dpmi_int. The only downside of doing so is that you don't get a protected-mode selector for the allocated buffer, but that selector is seldom if ever used by programs anyway. In addition to avoiding selector leaks, this method also works around a known bug in NT 4 whereby calling __dpmi_free_dos_memory will crash your program (I don't know if Windows 2000 solved this bug).