delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/09/11/04:00:34

Newsgroups: comp.os.msdos.djgpp
From: manni DOT heumann AT gmx DOT de (Manni Heumann)
Subject: Re: strdup() with delete[]
References: <8pgtns$sja$1 AT info DOT cyf-kr DOT edu DOT pl> <20000911010800 DOT C23829 AT chance DOT cz> <39BC7BD7 DOT 6A19D043 AT yahoo DOT com>
X-Newsreader: News Xpress 2.01
Mime-Version: 1.0
Date: Mon, 11 Sep 2000 07:57:40 GMT
NNTP-Posting-Host: dhcp33-228.uni-bielefeld.de
Message-ID: <39bc9070$1_1@news.uni-bielefeld.de>
X-Trace: 11 Sep 2000 09:57:36 +0200, dhcp33-228.uni-bielefeld.de
Lines: 27
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

djgpp AT delorie DOT com wrote:
>Can't you do it like this:
>        char *x=new char[255];
>        free(x);
>Will it work?
>I though it is the same meaning whether you use malloc or 'new', and the
>same meaning whether you free it or delete it. These should result in
>the same OS API, regardless of the language you use. 
>I have been deleting a strdup() from long time. That all was a waste!!!
>

The point is, that you cannot be sure what delete will do. It 
could simply call free, but there is no guarantee. If you are 
using new to get your memory, free it with delete.
Otherwise you might (by accident) do something like this:
SomeClass* x = new SomeClass [n];
..
free (x);

This will definitely not do what you want.


--

Manni

"Life would be much easier if I had the source code."

- Raw text -


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