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