delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/09/17/04:45:37

From: "Rafał Maj" <r_maj AT poczta DOT onet DOT pl>
Newsgroups: comp.os.msdos.djgpp
Subject: FINALY: delete/delete[] with build-in-types/user-classes
Date: Sun, 17 Sep 2000 10:00:28 +0200
Organization: Academic Computer Center CYFRONET AGH
Lines: 25
Message-ID: <8q1tn2$iv6$1@info.cyf-kr.edu.pl>
NNTP-Posting-Host: d-94-53-20.cyfronet.krakow.pl
X-Trace: info.cyf-kr.edu.pl 969177634 19430 149.156.1.180 (17 Sep 2000 08:00:34 GMT)
X-Complaints-To: news AT cyf-kr DOT edu DOT pl
NNTP-Posting-Date: 17 Sep 2000 08:00:34 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Hi,
because my last question about delete / delete[] caused big discusion with
meany diffrent opinions, I wan't to check, if finaly I understand it...
(probably not ;)
1) "s" is a pointer to array, maked like:  myclass* s = new myclass[100];
   a)  delete []s    will not only free memory, but alsow call destructor
for each of 100 objects "myclass"
   b) using delete s;  is probably wrong, because none destructor will be
called. But all memory 100*sizeof(myclass) will be freed ?
2) with   char *s = new char[100]  I can use :
  a) delete []s;  but it isn't necessarly, when char doesn't have any
destructor
  b) delete s;  is good
3) and what with   char* s = malloc(sizeof(char)*100); ?
   a) free - typical
   b) can I use delete ?
   c) can I use delete [] ?
4) because strdup() uses malloc,   char *s=strdup(S); should be "deleted"
same way as in question 3

Many Thanks,
Rafal



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019