home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / cplus / 13482 < prev    next >
Encoding:
Text File  |  1992-09-10  |  1.4 KB  |  33 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!taumet!steve
  3. From: steve@taumet.com (Steve Clamage)
  4. Subject: Re: malloc or new in c++
  5. Message-ID: <1992Sep10.170132.553@taumet.com>
  6. Organization: TauMetric Corporation
  7. References: <gate.8NagqB1w165w@toz.buffalo.ny.us> <6649@lhdsy1.lahabra.chevron.com>
  8. Date: Thu, 10 Sep 1992 17:01:32 GMT
  9. Lines: 22
  10.  
  11. hwrvo@kato.lahabra.chevron.com (W.R. Volz) writes:
  12.  
  13. |Let me get this straight: Are you saying that there is a problem of using
  14. |malloc in a c++ program? I realize that if I malloc some memory, then
  15. |I need to free it with free(). And if a create a new object with new, then I
  16. |delete with delete. I wouldn't 'free' an object allocated with 'new' and 
  17. |'delete' an object allocated with 'malloc'. But if there is an incompatibility 
  18. |in c++ between (malloc,free) and (new,delete), I don't know how one can mix
  19. |any program that uses both allocatation schemes.
  20.  
  21. As long as you do what you have said here, there should be no problem.
  22. I don't know of a C++ implementation that won't allow malloc/free
  23. and new/delete in the same program.  The C++ Standard will require
  24. that these be allowed to appear in the same program.
  25.  
  26. You do have to be careful about not using malloc for an object with a
  27. constructor or destructor, and about not mixing styles on the same
  28. object.
  29. -- 
  30.  
  31. Steve Clamage, TauMetric Corp, steve@taumet.com
  32. Vice Chair, ANSI C++ Committee, X3J16
  33.