home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16359 < prev    next >
Encoding:
Internet Message Format  |  1992-11-16  |  1.6 KB

  1. Xref: sparky comp.lang.c++:16359 comp.lang.c:16598
  2. Path: sparky!uunet!dtix!darwin.sura.net!Sirius.dfn.de!solaris.rz.tu-clausthal.de!news!andreas
  3. From: andreas@appel012.hydromech.uni-hannover.de (Andreas Dunker)
  4. Newsgroups: comp.lang.c++,comp.lang.c
  5. Subject: Re: Delete a dynamically allocated 2-dim'l array?
  6. Message-ID: <1992Nov16.142710.17104@newsserver.rrzn.uni-hannover.de>
  7. Date: 16 Nov 92 14:27:10 GMT
  8. References: <BxM7EC.BvE@math.uwaterloo.ca>
  9. Sender: news@newsserver.rrzn.uni-hannover.de (News Service)
  10. Organization: RRZN
  11. Lines: 36
  12. X-Newsreader: Tin 1.1 PL4
  13.  
  14. xjzhu@math.uwaterloo.ca (Xiaojun Zhu) writes:
  15. : Q: How to delete a dynamically allocated 2-dimensional array?
  16. :  
  17. : More specifically, I have:
  18. :    int row, column;
  19. :    int **array;
  20. [ deleted ]
  21. : Can I simply say:
  22. :    delete array;
  23.  
  24. You only have "free'd" the pointer to th array of pointers,
  25. but the memory is still allocated.
  26.  
  27. : Or should I say:
  28. :    for(i=row-1; i>=0; i--)
  29. :       delete array[i];
  30. :    delete array;
  31.  
  32. This is the right way.
  33.  
  34. ______________________________________________________________________________
  35.  
  36. Andreas Dunker                                Institut fuer Stroemungsmechanik
  37. andreas@appel012.hydromech.uni-hannover.de          und elektronisches Rechnen
  38.                                                                    im Bauwesen
  39.                                                          Universitaet Hannover
  40. 2B  |  ! 2B  (W. Shakespeare)                                     West Germany
  41. ______________________________________________________________________________
  42.