home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!uwm.edu!ogicse!das-news.harvard.edu!cantaloupe.srv.cs.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!sm86+
- From: sm86+@andrew.cmu.edu (Stefan Monnier)
- Newsgroups: comp.unix.questions
- Subject: Re: Does free() really free?
- Message-ID: <oeeD5OC00awMEEimk2@andrew.cmu.edu>
- Date: 5 Sep 92 09:41:46 GMT
- Article-I.D.: andrew.oeeD5OC00awMEEimk2
- References: <9209051620.AA02618@ucbvax.Berkeley.EDU>
- Organization: Junior, Math/Computer Science, Carnegie Mellon, Pittsburgh, PA
- Lines: 58
- In-Reply-To: <9209051620.AA02618@ucbvax.Berkeley.EDU>
-
- Excerpts from netnews.comp.unix.questions: 5-Sep-92 Does free() really
- free? Simon Marshall@sequent.c (1471)
-
- > Or: How do I find out the real size of a running process?
-
- > Hi all. This is really a question about the Sequent's shfree(), but
- > in tests it seems to apply to other machines and free() in general.
- > Please can anyone give a knowledgable answer?
-
- > If I malloc(), then free(), the SZ (SIZE) column of ps does not show
- > the expected fall. I don't believe that the system ignores freed space,
- > but then again I know that software that I have written thrashes
- > machines, despite the fact that most of the memory malloc()ed is
- > subsequently free()ed.
-
- > On our Sequent and Suns, for example, once the SZ column shows
- > 70Meg+, you can see the machines thrash. But I can work out that the
- > actual unfreed memory only amounts to at most 15Meg.
-
- > So, please could anyone tell me what is going on here? Does free()
- > actually free, and is the SZ column of ps reliable in any way? Or is
- > free() working as expected, ps lying, but 15Meg is too much? Surely
- > not?! I'd welcome anything emailed/posted. (Except unhelpful questions
- > of the order `why are you mallocing then freeing so much' etc. :-)
-
- > Thanks in advance, Simon.
- > _______________________________________________________________________________
- > Simon Marshall, Dept. of Computer Science, University of Hull, Hull HU6
- > 7RX, UK
- > "Football isn't about life and death. It's more important than that." Bill
- > Email: S.Marshall@Hull.ac.uk Phone: +44 482 465181 Fax: 466666 Shankley
-
-
- I'm not a Unix wizard: I used to have an Atari ST.
-
- But Unix may be a bit the same on this point:
- A alloc() is not a call to the OS but a library function. This
- function request memory from the OS but in 'big' blocks
- (cause the malloc() of the OS is a bit too complex, especially
- on Unix, where it has to deal with VM...).
- When there is some place left in one of the blocks, the alloc()
- just returns it (and marks it busy), else, it calls malloc() to
- get a new block and marks the needed part of it as busy.
-
- When you call free(), it will mark the corresponding region as
- free. But the block in which that region is may not be fully
- free, so that it is not released to the OS: it is free for the
- prg but not for the OS.
-
- This is maybe what is happening to you: your 15MB are
- distributed among 70MB of blocks !
-
-
- Stefan Monnier
-
- -----------------------------------------------------
- -- On the average, people seem to be acting normal --
- -----------------------------------------------------
-