delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/02/02:33:04

From: "Vyacheslav O. Myskin" <V DOT O DOT Myskin AT inp DOT nsk DOT su>
Organization: BINP RAS, Novosibirsk, Russia
To: djgpp AT delorie DOT com
Date: Sun, 2 Mar 1997 13:23:46 +0600
Subject: Re: quick malloc question
Reply-To: V DOT O DOT Myskin AT inp DOT nsk DOT su
Message-Id: <2A24A4042B8@csd.inp.nsk.su>

On  1 Mar 97 at 23:37, Cristovao Braga wrote:

>
> I was wondering: if I allocate some memory with malloc () or an equivalent
> function and then quit the program without calling free (), will this
> memory be freed automatically?

Yes it will.

>
> I searched the djgpp docs and all I could find was this:
>
> "This function allocates a chunk of memory from the heap large enough to
> hold any object that is SIZE bytes in length.  This memory must be
> returned to the heap with `free' (*note free::.)."
>
> Please note that it says "must".

"Must" if you want to use it in the same program before exit, or it
may run out of memory.

>
> Then I conducted the following test: I run the program which source is
> below under both Win95 and plain DOS with CWSDPMI. My computer has 32 MB of
> RAM and in both cases I run it about 30 times in a row. The available
> memory as reported by MEM.EXE did not shrink a single bit nor there was a
> single indication of virtual memory usage like disc activity.
>

*The FAQ stuff* - malloc (not malloc itself, but DPMI server) just marks
a region of memory as 'used' in it's structures, and you will not see any
disk activity until you try to access this region (read or write). At least
that's how I understand it.

> Any comments?
>
> Cristovao Braga.
>
> --- starts here ---
>
> #include <stdlib.h>
>
> char *p;
>
> main ()
>    {
>       p = (char *) malloc (5 * 1024 * 1024);
>    }
>
>______________________________________________
Vyacheslav O. Myskin  <myskin AT inp DOT nsk DOT su>
Budker Institute of Nuclear Physics (BINP RAS)
Novosibirsk, Russia

- Raw text -


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