delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/09/16/16:45:12.1

From: dontmailme AT iname DOT com (Steamer)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Repost: free() DOESN´T return memory to the system
Date: Sat, 16 Sep 2000 20:35:32 GMT
Organization: always disorganized
Lines: 49
Message-ID: <39c3d96d.43762513@news.freeserve.net>
References: <969134507 DOT 984557 AT osiris DOT esoterica DOT pt>
NNTP-Posting-Host: modem-227.north-carolina.dialup.pol.co.uk
X-Trace: newsg2.svr.pol.co.uk 969136533 12298 62.137.84.227 (16 Sep 2000 20:35:33 GMT)
NNTP-Posting-Date: 16 Sep 2000 20:35:33 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Newsreader: Forte Free Agent 1.11/32.235
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hiper M.A.R. wrote:

> Has it is clearly stated in Faq15_2.html:
> "When you call free, DJGPP library doesn't return memory to the
> system, it just adds it to its internal pool of free pages. So, from
> the point of view of the DPMI server, these pages are not "free". "
> My question is:
> Isn't there some way to return memory to system (besides quitting the
> program!)?
> About Win95, it will give as much as the program needs, BUT only
> until the memory and the swap file aren't EXAUSTED.
> If you have a program that is constantly allocatting memory, and
> freeing it when he no longer needs it, soon the resources are exauted,
> because the DPMI won't "see" they have been freed.

You have misunderstood the way it works.  Memory that is freed
can be reused by your program (through malloc, calloc or realloc).
Because it isn't returned to the DPMI server it can't be reused by
a _different_ program, but that's rarely a problem.

> Thus using free() has no impact, purelly a cosmetic sense.

You can easily see that this is nonsense by running a simple
test program:

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

int
main(void)
{
    void *ptr;
    long i;

    for(i=0;i<1000000;i++) {
        ptr = malloc(1024*1024);
        if (!ptr) {
            printf("Out of memory!\n");
            return 0;
        }
        free(ptr);
    }
    printf("Successfully malloc'ed a million megabytes!\n");
    return 0;
}

(Try it also without the free(ptr) and see the difference.)

S.

- Raw text -


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