Date: Sun, 24 Sep 1995 09:51:43 +0200 (IST) From: Eli Zaretskii To: Patrick Steele Cc: djgpp AT sun DOT soe DOT clarkson DOT edu Subject: Re: coreleft() in DJGPP? On 21 Sep 1995, Patrick Steele wrote: > I'm porting an app from Borland C++ 4.5 and need to check for how much > memory is left (I don't want to fall below a certain limit). BC had > a "coreleft()" function which would let me know how much memory is > free. Is there a comparable function in DJGPP? Not really. You can use some of the following functions (declared on and documented in the libcref.i Info file): int _go32_dpmi_get_free_memory_information(_go32_dpmi_meminfo *info); u_long _go32_dpmi_remaining_physical_memory(void); u_long _go32_dpmi_remaining_virtual_memory(void); However, these don't report on memory which is free in the memory pool used by malloc(), only the memory which wasn't requested from the system by brk()/sbrk(), so they don't really tell you how much free memory do you have. Personally, I don't think this to be too much of an omission, for two reasons: 1) Different extended memory providers (XMS, VCPI, DPMI) have their peculiar bugs/features when you ask for memory, so it's next to impossible to tell exactly how much memory can you ask before you get NULL from malloc(). (For example, under some versions of Windows and QDPMI you can never allocate more than half of available memory in a single chunk.) 2) When you have virtual memory, you should generally worry much less about how much do you have. Isn't this what virtual memory is all about? If you care about the physical memory (for performance reasons), then you can test the available physical memory at the program start-up, with one of the functions mentioned above.