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

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!spool.mu.edu!sdd.hp.com!ux1.cso.uiuc.edu!m.cs.uiuc.edu!sunb10.cs.uiuc.edu!sparc10.cs.uiuc.edu!pjl
  3. From: pjl@sparc10.cs.uiuc.edu (Paul Lucas)
  4. Subject: Re: help
  5. Message-ID: <1992Sep14.022715.1460@sunb10.cs.uiuc.edu>
  6. Sender: news@sunb10.cs.uiuc.edu
  7. Organization: University of Illinois at Urbana-Champaign
  8. References: <1992Sep13.164046.24676@njitgw.njit.edu>
  9. Distribution: usa
  10. Date: Mon, 14 Sep 1992 02:27:15 GMT
  11. Lines: 31
  12.  
  13. In <1992Sep13.164046.24676@njitgw.njit.edu> jxd7299@hertz.njit.edu (Jing X Ding) writes:
  14.  
  15.  
  16. >    PROD *A;//PROD is a defined class
  17. >       :
  18. >       :
  19. >    for (...){
  20. >    A=(PROD*)new char [totalprod*sizeof(PROD)];//totalprod is a const
  21. >       :
  22. >       :
  23. >     Place 1
  24. >    }
  25. >     Place 2
  26.  
  27. >The problem is :(1) Where can I use destructure to free memory (Place 1 or
  28. >Place 2)? (2) How to write the destructure?
  29.  
  30. *****>    new is not malloc; you don't calculate the size nor cast.
  31.  
  32.         for (...) {
  33.             A = new PROD[ totalprod ];
  34.             // ...
  35.             delete[] A;
  36.         }
  37.     
  38.     I suggest reading the relevant section on new/delete in a C++
  39.     book.
  40. -- 
  41.     - Paul J. Lucas                University of Illinois    
  42.       AT&T Bell Laboratories        at Urbana-Champaign
  43.       Naperville, IL            pjl@cs.uiuc.edu
  44.