home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16405 < prev    next >
Encoding:
Text File  |  1992-11-17  |  1.8 KB  |  53 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!ukma!usenet.ins.cwru.edu!agate!iat.holonet.net!rkinder
  3. From: rkinder@iat.holonet.net (Robert J. Kinder)
  4. Subject: Re: Using delete with arrays - help please!
  5. Message-ID: <BxuI1G.3Mo@iat.holonet.net>
  6. Organization: HoloNet (BBS: 510-704-1058)
  7. References: <1992Nov16.023852.24205@gopher.dosli.govt.nz>
  8. Date: Tue, 17 Nov 1992 05:32:02 GMT
  9. Lines: 42
  10.  
  11. Borland C++ 3.1 has two implementations of operator new() and delete(). 
  12. These may be found in the files vnew.cpp, vdel.cpp, new.cpp, and del.cpp.
  13.  
  14. The vnew.cpp & vdel.cpp are for 'vector' (a.k.a. arrays) new and delete.
  15.  
  16. The Borland C++ runtime library routine _vector_new() is called to
  17. allocate arrays of objects having constructors.  _vector_delete() is
  18. called to deallocate arrays of objects having destructors.  These two
  19. routines eventually call _new() and _delete() to do the actual memory
  20. allocations.
  21.  
  22. The statements
  23.  
  24.    char str[80] = new char[80];
  25.    delete [] str;
  26.  
  27. allocate and free an array of chars.  There are no constructor or
  28. destructor methods to be called.
  29.  
  30. The statements
  31.  
  32.    myClass stuff[5] = new myClass[5];
  33.    delete [] stuff;
  34.  
  35. are handled via the vector new and delete functions.  The myClass objects
  36. presumably have constructors and destructors that need to be called.
  37.  
  38. You're getting a NULL pointer assigment error if you try
  39.  
  40.    delete stuff;
  41.  
  42. (the array [] brackets are omitted) probably because vector new & delete
  43. saves the number of objects in the array by modifying the memory pointer
  44. value returned by the basic new() and delete().
  45.  
  46.  
  47.  
  48. -- 
  49. // rkinder@holonet.net            International Software Solutions, Inc.  -
  50. // Robert J. Kinder, Jr.                             Boca Raton, Florida  -
  51. //                                                        1-800-788-4774  -
  52. // "We're having a real Ted Bundy day here." - C. Bernholtz
  53.