delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1994/05/10/07:15:31

Subject: Re: malloc under DV/X
To: ronis AT onsager DOT chem DOT mcgill DOT ca (David Ronis)
Date: Tue, 10 May 1994 10:13:35 +0200 (MET DST)
From: Henrik Storner <storner AT olicom DOT dk>
Cc: djgpp AT sun DOT soe DOT clarkson DOT edu

David Ronis writes:

> I use djgpp under Desqview/X.  For the most part, I use it when I need to 
> access large arrays.  Thinks work correctly, but I've noticed that malloc
> allocates system memory irreversibly; for example, free doesn't seem to return
> the memory to the system (DV/X) until the program exits, or if I have a large
> local array in a function, this memory is not returned to the system when
> the program exits.

What version of DV/X & DJGPP are you using ? I don't see this behaviour on
my system, which is running QEMM 7.04, DV/X 2.0 and DJGPP 1.11.maint5 .
Are you letting go32 use DPMI (I don't) ?

I tried it out with the following program:

#include <stdio.h>
#include <stdlib.h>

unsigned char *p;
char s[20];

void main(void)
{
   int i,j;
   char *q;

   /* Loop three times, and see if the memory numbers change */
   for (i=0; i<3; i++) {
      /* DVP for the window sets a max. of 4 MB, so this will cause
       * go32 to swap, but only when the memory is accessed 
       */
      p = malloc(1024*1024*6);

      q = p;
      for (j=0; j<6*1024; j++) {
          memset(q, j, 1024);
          q += 1024;
      }

      sprintf(p, "Hello world, take %u\n", i); puts(p);

      free(p);
      printf("Hit any key to continue "); gets(s);
   }
}


It is true, that the EMS memory allocated by go32 doesn't get freed until
the program terminates - I guess this is just the way that go32 handles
memory allocation: Once it has got some memory, it hangs on to it until
it terminates - free and malloc then use whatever memory is already
allocated, or allocate more if needed.

I don't know how much work it would take to alter go32 so that it would
really free up whatever memory was freed - my guess is that it might be
non-trivial, as the free() algorithm would also have to take care of the
freed space not necessarily being contiguous. Thus, freeing up the EMS memory
would require shuffling other parts of allocated memory around, and then
keeping track of what points to that memory.
-- 
Henrik Storner        | "Man is the best computer we can put aboard a space-
(storner AT olicom DOT dk)   |  craft ... and the only one that can be mass produced 
System Engineering    |  with unskilled labor."
Olicom Denmark        |                                   Wernher von Braun

- Raw text -


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