X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f Date: 22 Oct 2003 07:42:35 +0200 Message-Id: From: Eli Zaretskii To: djgpp AT delorie DOT com In-reply-to: (intrepid_x AT hotmail DOT com) Subject: Re: Detecting Memory Leaks References: 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: intrepid_x AT hotmail DOT com (Dave T) > Newsgroups: comp.os.msdos.djgpp > Date: 21 Oct 2003 15:09:40 -0700 > > My question is: What function do I use to check the available heap > memory? The released version of the DJGPP library doesn't have such a facility. About the only way to do that is to get the source of malloc and hack it to add this capability. (If you want to do this, you will find malloc.c inside djlsr203.zip.) The development sources of the next version of DJGPP include a function called `mallinfo' that returns information about used and free memory blocks in the heap. You can find an alpha release of the next DJGPP version here: ftp://ftp.delorie.com/pub/djgpp/alpha/v2/djdev204.zip (Warning: this is alpha software!) In there, you will find a new version of the library and new headers that needs to be installed instead of what you have now. Alternatively, you could put your create-delete code inside a loop, run it many times, and see if the value returned by "sbrk(0)" goes up with time. If your code doesn't suffer from leaks or memory fragmentation, the value of sbrk(0) should get increased on the first iteration thru the loop, and then stay put. > Does anybody have any general advice for avoiding memory leaks? The way you want to do it _is_ the general way.