Mail Archives: djgpp/2000/09/16/16:45:12.1
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 -