home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / unix / aix / 11871 < prev    next >
Encoding:
Internet Message Format  |  1992-11-24  |  1.8 KB

  1. Path: sparky!uunet!noc.near.net!bigboote.WPI.EDU!mickey!cwright
  2. From: cwright@mickey.WPI.EDU (Charles R. Wright)
  3. Newsgroups: comp.unix.aix
  4. Subject: Proper use of malloc/calloc/free
  5. Date: 24 Nov 1992 02:53:19 GMT
  6. Organization: Worcester Polytechnic Institute, Worcester, MA
  7. Lines: 34
  8. Distribution: world
  9. Message-ID: <1es5evINNc1b@bigboote.WPI.EDU>
  10. NNTP-Posting-Host: mickey.wpi.edu
  11.  
  12.  
  13. Hi,
  14.  
  15. Either I am grossly misunderstanding the use of malloc/calloc and
  16. free, or there's something wrong...
  17.  
  18. I do a lot of numerical programming.  I use the "Numerical Recipes in
  19. C" method of allocating arrays for data, and this has been quite
  20. successful for me.  Recently, folks in our lab got very wary of the
  21. use of malloc, and decided calloc was better.  Apparently, it has to
  22. do with calloc actually needing to access all the elements of the
  23. allocated memory in order to zero them, where malloc simply hands you
  24. a pointer - no other accesses of the memory.  The fear is that malloc
  25. will give you a pointer to memory that may not even be all there...
  26.  
  27. Well, in the blessed man pages it says that "the free subroutine frees
  28. a block of memory previously allocated by the malloc subroutine."  It
  29. says this for AIX (3.2, RS 6000), and it says something similar on an
  30. Ultrix machine.
  31.  
  32. Excuse me though, what's the proper way to free memory allocated by
  33. calloc???  I've been using calloc and free together anyway, in spite
  34. of the man page.  But now, I'm noticing (using that great "monitor"
  35. program) that memory use in my large numerical program is a
  36. monotonically increasing function!  So it seems that the calls to free
  37. are no-ops!
  38.  
  39. Someone please explain.
  40.  
  41. Thanks a million,
  42.  
  43. Charles Wright        Research Assistant, Machine Vision Lab, ECE Dept.
  44. cwright@ee.wpi.edu    De facto system manager for an IBM RS-6000
  45.      "To have so many windows on my screen, I lose consciousness"
  46.