From: Shawn Hargreaves Newsgroups: comp.os.msdos.djgpp Subject: Re: Help:Memory Allocation Date: Tue, 5 May 1998 20:03:07 +0100 Organization: None Message-ID: References: <354FDA55 DOT 948BC6E7 AT mailexcite DOT com> NNTP-Posting-Host: talula.demon.co.uk MIME-Version: 1.0 Lines: 37 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Wai Teng writes: >What is the difference between malloc and __dpmi_allocate_linear_memory? malloc() is a standard C function, which is portable to any compiler and returns a pointer that you can use directly from your code. __dpmi_allocate_linear_memory() is a DPMI 1.0 function (so it will not work with DPMI 0.9 servers like win95), and is extremely non-portable. Only mess with this in very specialised situations, and if you know exactly what you are doing. Normal programs should use malloc() for all their memory allocation. >If I use __dpmi_allocate_linear_memory, then how do I free the memory >once I'm done with it? By calling __dpmi_free_memory(). >Which should I use if I only want physical memory, not virtual memory >paged from theswap file? Use a different compiler :-) Virtual memory is provided by the DPMI host, not the individual program, so there is no standard way to disable this. You could use a DPMI server like cwsdpr0 that doesn't provide virtual memory, but that isn't always possible (eg. if your program is run under win95, it must always use the win95 DPMI). Alternatively you could lock the memory after you allocate it, but this seems like rather a pointless thing to do. Virtual memory is a Good Thing: having it available doesn't hurt as long as your program fits entirely into physical memory, and if you do run out of RAM, I think some ocassional swapping is much better than a crash or aborting with an "out of memory" error :-) -- Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/ "Pigs use it for a tambourine" - Frank Zappa