Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!bellcore!uunet!microsoft!jimad From: jimad@microsoft.UUCP (Jim ADCOCK) Newsgroups: comp.lang.c++ Subject: Re: Is it okay to use delete after malloc? Message-ID: <70516@microsoft.UUCP> Date: 6 Feb 91 22:27:16 GMT References: <1991Jan29.150219.28884@athena.mit.edu> <574@taumet.com> Reply-To: jimad@microsoft.UUCP (Jim ADCOCK) Distribution: usa Organization: Microsoft Corp., Redmond WA Lines: 16 In article <574@taumet.com> steve@taumet.com (Stephen Clamage) writes: |ahodgson@athena.mit.edu (Antony Hodgson) writes: | |>If I create a string using one of the library routines such as strdup, |>is it then acceptable to use delete, or is free() required? | |Using 'delete' on a pointer is not guaranteed to work if the pointer |was not obtained from 'new'. If space is acquired by malloc(), you |should return it with free(). I agree today. The ANSI-C++ committee is looking into what interactions should be allowed/disallowed in terms of new vs malloc, and stream i/o vs stdio, so things could become easier on programmers in the future. Today, things are implementation defined, and you're more likely of success if you match your malloc/free's, new/delete's, and new[]/delete[]'s.