From: "Vyacheslav O. Myskin" 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 > > char *p; > > main () > { > p = (char *) malloc (5 * 1024 * 1024); > } > >______________________________________________ Vyacheslav O. Myskin Budker Institute of Nuclear Physics (BINP RAS) Novosibirsk, Russia