home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / question / 10770 < prev    next >
Encoding:
Text File  |  1992-09-07  |  1.5 KB  |  54 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!rpi!fitzgb
  3. From: fitzgb@mml0.meche.rpi.edu (Brian Fitzgerald)
  4. Subject: Re: Does free() really free?
  5. Message-ID: <hf1yh5=@rpi.edu>
  6. Summary: no
  7. Nntp-Posting-Host: mml0.meche.rpi.edu
  8. Organization: Rensselaer Polytechnic Institute, Troy, NY
  9. References: <9209051620.AA02618@ucbvax.Berkeley.EDU>
  10. Date: Sat, 5 Sep 1992 19:48:55 GMT
  11. Lines: 41
  12.  
  13. Simon Marshall writes:
  14. >    So, please could anyone tell me what is going on here?  Does free()
  15. >    actually free, and is the SZ column of ps reliable in any way?  Or is
  16.  
  17. malloc() uses the sbrk() system call to get more space when it needs
  18. it.  free() performs no system calls, and merely frees the space for
  19. subsequent reuse by malloc.
  20.  
  21. I base my comments on perusal of the malloc sources in wuarchive.wustl.edu:
  22. /archive/systems/unix/4.3bsd-reno/lib/libc/stdlib
  23.  
  24. Brian
  25.  
  26. void
  27. free(cp)
  28.     void *cp;
  29. {   
  30.       register int size;
  31.     register union overhead *op;
  32.  
  33.       if (cp == NULL)
  34.           return;
  35.     op = (union overhead *)((caddr_t)cp - sizeof (union overhead));
  36. #ifdef DEBUG
  37.       ASSERT(op->ov_magic == MAGIC);        /* make sure it was in use */
  38. #else
  39.     if (op->ov_magic != MAGIC)
  40.         return;                /* sanity */
  41. #endif
  42. #ifdef RCHECK
  43.       ASSERT(op->ov_rmagic == RMAGIC);
  44.     ASSERT(*(u_short *)((caddr_t)(op + 1) + op->ov_size) == RMAGIC);
  45. #endif
  46.       size = op->ov_index;
  47.       ASSERT(size < NBUCKETS);
  48.     op->ov_next = nextf[size];    /* also clobbers ov_magic */
  49.       nextf[size] = op;
  50. #ifdef MSTATS
  51.       nmalloc[size]--;
  52. #endif
  53. }
  54.