www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/11/08/17:33:05

From: Elliott Oti <e DOT oti AT stud DOT warande DOT ruu DOT nl>
Newsgroups: comp.os.msdos.djgpp
Subject: Q: Problems with free()
Date: Fri, 08 Nov 1996 11:47:07 -0800
Organization: Academic Computer Centre Utrecht, (ACCU)
Lines: 37
Message-ID: <32838E3B.3EB4@stud.warande.ruu.nl>
NNTP-Posting-Host: warande1078.warande.ruu.nl
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Hi,
I'm busy writing a 3D graphics library, and I thought it was ripe
enough to run a lengthy test program. The test ran fine at first but crashed
suddenly after about 3 minutes. My rattling hard drive led me to suspect
memory shortage, and a few tests showed that this was indeed the case.
I made sure that all malloc'ed memory was freed, but the test
kept crashing. So I wrote the attached little program to test if free()
was indeed freeing malloc'ed memory.

The output showed that the malloc'ed memory was *not* freed, despite the
call to free().

The Borland C equivalent using coreleft() instead of _go32_dpmi_remaining_
physical_memory does return the correct amounts.

What's happening? Did I miss something somewhere? Any ideas ?
(Sorry if this has been discussed before, I must've missed it).

TIA,
Elliott.
-------------------- FREE() TEST BEGINS ---------------------------------
#include <dpmi.h>

void main()
{
int mem1,mem2,mem3;
char *b;
mem1 = _go32_dpmi_remaining_physical_memory();
b = (char *)malloc(1024*1024);
memset(b,5,1024*1024);    // Make sure memory *is* used 
mem2 = _go32_dpmi_remaining_physical_memory();
free(b);
mem3 = _go32_dpmi_remaining_physical_memory();
printf("\n%ld \n%ld \n%ld",mem1,mem2,mem3);
}

------------------- FREE() TEST ENDS -----------------------------------------

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019